Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleModuleLoader cannot resolve relative paths on the CLI #4085

Closed
KieranP opened this issue Dec 12, 2024 · 10 comments · Fixed by #4108
Closed

SimpleModuleLoader cannot resolve relative paths on the CLI #4085

KieranP opened this issue Dec 12, 2024 · 10 comments · Fixed by #4108
Labels
bug Something isn't working

Comments

@KieranP
Copy link

KieranP commented Dec 12, 2024

Describe the bug

Trying to run this code using Boa: https://github.com/KieranP/Game-Of-Life-Implementations/tree/master/typescript

import { World } from './world.js'; producing this error: Uncaught SyntaxError: expected token '.', got '{' in import.meta at line 1, col 8

export class World { producing this error: Uncaught SyntaxError: unexpected token 'export', primary expression at line 3, col 1

To Reproduce

Compile the Typescript to Javascript using tsc and then try to run boa play.js

Expected behavior

Should parse and run as expected. The code doesn't contain anything complex

Build environment (please complete the following information):

  • OS: Mac OS
  • Version: Sequioa 15.1.1
  • Target triple: arm64
  • Rustc version: 1.83.0
@KieranP KieranP added the bug Something isn't working label Dec 12, 2024
@KieranP
Copy link
Author

KieranP commented Dec 12, 2024

This is what I did to replicate:

brew install typescript
cargo install boa_cli
PATH=~/.cargo/bin:$PATH
git clone https://github.com/KieranP/Game-Of-Life-Implementations.git
cd Game-Of-Life-Implementations/typescript
tsc
boa play.js

I immediately get the Uncaught SyntaxError: expected token '.', got '{' in import.meta at line 1, col 8 error

@jedel1043
Copy link
Member

The cli will treat input files as scripts by default. To treat the files as modules, you need to use the -m flag:

boa play.js -m

@jedel1043 jedel1043 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2025
@KieranP
Copy link
Author

KieranP commented Jan 5, 2025

@jedel1043 Thanks for that. Getting this different error now:

Uncaught "relative path without referrer"

The line in question is:

import { World } from './world.js';

Tried searching this repo and google, but can't find anyone else experiencing this. Any suggestions?

@jedel1043
Copy link
Member

It is possible that the module resolver didn't use the correct root path to resolve the modules, so you can pass it explicitly with the --root flag:

boa play.js -m --root some/root/dir

If that still doesn't work, we can reopen this to track that bug.

@KieranP
Copy link
Author

KieranP commented Jan 5, 2025

@jedel1043 No luck using root, either with ., pwd, or explicit full path:

$ boa play.js -m --root .
Uncaught "relative path without referrer"

$ boa play.js -m --root $(pwd)
Uncaught "relative path without referrer"

$ boa play.js -m --root /Users/kieran/Work/gol_implementations/typescript/
Uncaught "relative path without referrer"

@jedel1043 jedel1043 reopened this Jan 5, 2025
@jedel1043
Copy link
Member

Reopening this to look at the issue.

@jedel1043 jedel1043 changed the title Issues with import / export SimpleModuleLoader cannot resolve relative paths on the CLI Jan 5, 2025
@jedel1043
Copy link
Member

Opened #4108 to fix the import error. However, note that after the fix the code is throwing ReferenceError: process is not defined, which is because we don't implement Node APIs on our runtime. Implementing that should probably be tracked by a separate issue.

@KieranP
Copy link
Author

KieranP commented Jan 5, 2025

@jedel1043 The use of process is to fetch an environment variable. If Boa has a different way to fetch those available, I'll bypass process and use that instead. Or there is no support for that currently?

@jedel1043
Copy link
Member

Yeah, no support for setting environment variables. Also I'm seeing that it also uses the performance object, which we also don't support.

We haven't added much things to the example runtime because developing a whole runtime is itself a lot of work that is separate from the development of the engine, so we depend on contributions for adding new features to it.

@KieranP
Copy link
Author

KieranP commented Jan 5, 2025

Understood. I'll circle back to Boa later in the year to see if a few of these things are available then. Unfortunately, I'm not proficient enough with Rust to help contribute in any meaningful way sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@KieranP @jedel1043 and others