Open Thundercraft5 opened 1 year ago
I'm facing the same issue as I'm trying to debug TypeScript
Need to bump this, it is quite annoying to see these lines
(node:50692) 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)
Shouldn't be that hard to convert to an import flag and expose that.
Hi, I work on Node.js. The --loader
flag is undocumented and there’s a good chance it will be removed in the future (along with --experimental-loader
). For a few years now we’ve been encouraging people to migrate to --import
.
To do so, you could create a new export from your package that calls node:module
‘s register
. You could create it as a CommonJS file so that it would work with either --import
or --require
, along these lines:
const { register } = require('node:module');
const { pathToFileURL } = require('node:url');
register('./esm.mjs', pathToFileURL('./'));
This file could also register the CommonJS hooks if you want to cover everything; and then your README wouldn’t need separate instructions for CommonJS and ESM.
If you create this and update your README accordingly, you will be future-proofing your package and removing reliance on Node experimental flags.
Are there any reason why this should not be implemented?
ts-node
is on the not-usable side of things if it forces us into deprecated Nodejs flags.
Desired Behavior
Should work exactly as node's
--import
flag, optionally an-I
alias.Alternatives you've considered
Running
node --loader ts-node/esm
with a local file path results in an error:Additional context
Node.js recently added the
--import
flag in v19.