experimental-loader to register
Closed this issue · 6 comments
I just started getting a new version of this error all the time when I run mocha with TypeScript using ESM modules.
Possibly due to using the latest node/npm.
Anyone else seeing this?
(node:38547) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--
import 'data:text/javascript,
import { register } from "node:module";
import { pathToFileURL } from "node:url";
register("ts-node/esm", pathToFileURL("./"));
'
--
(Use `node --trace-warnings ...` to show where the warning was created)
Possibly related to:
- Challenges migrating from --experimental-specifier-resolution=node to custom loader --loader
- nodeJS v19 drops support for --es-module-specifier-resolution=node which makes it harder to run transpiled TypeScript [duplicate]
- https://github.com/nodejs/loaders
This team is spun off from the Modules team. We aim to implement the use cases that went unfulfilled by the initial ES modules implementation that can be achieved via loaders.
Current .mocharc.json
{
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"url" : "https://stackoverflow.com/questions/64261239/mocha-tests-with-esm-support-for-native-es6-modules"
}
Can use:
npx mocha "test/ops/*" --loader=ts-node/esm
but still get warning.
First official notice I've seen that 'import' is replacing 'loader' in node:
Is --loader going away?
Sorta, it's going off-thread – so if you use it to e.g. define a global variable, it will be defined on the loader thread global scope and won't be available in the REPL anymore – but once this land, --import would be available and a better fit for your use-case.
Some details about 'register' at:
https://nodejs.org/api/module.html