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

"import" fails if file extension is not included #712

Open
zikifer opened this issue Mar 8, 2023 · 2 comments
Open

"import" fails if file extension is not included #712

zikifer opened this issue Mar 8, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@zikifer
Copy link

zikifer commented Mar 8, 2023

When importing a local (non-NPM) module the import fails if the file extension is not included. For example
import { Worker } from './worker';

If "js.commonjs-require" is "false" the error is Error: Error reading: /path/to/file/worker
If "js.commonjs-require" is "true" the error is TypeError: Module not found: './worker'

Example attached.
graaljs-import.zip

To run: mvn package exec:java

Expected: It should be able to resolve ./worker to ./worker.js, as node does.

@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Mar 13, 2023
@oubidar-Abderrahim oubidar-Abderrahim added the bug Something isn't working label Mar 13, 2023
@oubidar-Abderrahim
Copy link
Member

Hi, Thank you for reaching out, we'll take a look into it shortly.

@eleinadani
Copy link
Contributor

I had a quick look at your example, and -- if I am not mistaken -- node.js also throws an error with import './worker' in your case:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/danieleb/Downloads/graaljs-import/src/main/resources/worker' imported from /Users/danieleb/Downloads/graaljs-import/src/main/resources/main.mjs
Did you mean to import ../worker.js?

In any case, you can use a Truffle FS to customize how ES modules are loaded, and there is no need to use js.commonjs-require to load non-NPM modules like in your case. We have an example here, and in our unit tests.

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

No branches or pull requests

3 participants