-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
The node flag -r doesn't work in ESM mode, it translates it to a require() but it should be import.
Would it be possible to use a loader to inject a module? However, the loaded module needs to pass through babel. I was thinking to maybe add the imports in front of the translated code of the first file that @node-loader/babel loads?
The use case is a repl that includes some extra globals. In pre-ESM it was just a matter of adding -r ./inject-globals but now the only way is to type await import('./inject-globals.js') manually (*).
(*): and I'm actually doing that by calling a ioctl from Perl like so:
$ perl -e 'ioctl(STDIN, 0x5412, $_) for split "", "await import('"'"'$ARGV[0]'"'"')\n";' ./inject-globals.js; node --loader @node-loader/babel
await import('./inject-globals.js')
(node:495354) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Welcome to Node.js v16.14.2.
Type ".help" for more information.
> await import('./inject-globals.js')
[... it loads]
Metadata
Metadata
Assignees
Labels
No labels