- Version: v8.8.0
- Platform: macOS
- Subsystem: ES Modules
Assuming the following files:
// main.mjs
import {x} from './not-a-module.js'
// not-a-module.js
export const x;
One would expect that node --experimental-modules main.mjs would throw an error that not-a-module is not an ES module and thus does not support export. Rather, it throws this error:
SyntaxError: The requested module does not provide an export named 'x'
at checkComplete (internal/loader/ModuleJob.js:86:27)
at moduleJob.linked.then (internal/loader/ModuleJob.js:69:11)
at <anonymous>
Note that running not-a-module.js as the main module does throw the expected error, i.e. node --experimental-modules not-a-module.js throws an err: SyntaxError: Unexpected token export.
Also note that node -r @std/esm does the right thing. Just sayin' :-).
Assuming the following files:
One would expect that
node --experimental-modules main.mjswould throw an error thatnot-a-moduleis not an ES module and thus does not supportexport. Rather, it throws this error:Note that running
not-a-module.jsas the main module does throw the expected error, i.e.node --experimental-modules not-a-module.jsthrows an err:SyntaxError: Unexpected token export.Also note that
node -r @std/esmdoes the right thing. Just sayin' :-).