graaljs
graaljs copied to clipboard
"import" fails if file extension is not included
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.
Hi, Thank you for reaching out, we'll take a look into it shortly.
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.