TheSwanFactory/hclang

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)

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:

nodejs/node#44094

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

Sample log file

ts-esm.txt

Proposed import

ts-esm-js.txt