Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tsx to avoid loader deprecation #208

Closed
drernie opened this issue Aug 25, 2024 · 4 comments
Closed

Use tsx to avoid loader deprecation #208

drernie opened this issue Aug 25, 2024 · 4 comments

Comments

@drernie
Copy link
Contributor

drernie commented Aug 25, 2024

(node:32333) 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)

@drernie
Copy link
Contributor Author

drernie commented Aug 25, 2024

As the warning suggests, you should replace the --loader ts-node/esm flag with the one suggested in the warning, and the warning will disappear. FWIW there's an open issue on the ts-node repo to allow users to use a simpler syntax: TypeStrong/ts-node#2072

@drernie
Copy link
Contributor Author

drernie commented Aug 25, 2024

To make the command more ergonomic, create a file that registers module resolution hooks. Let’s name the file register.js.

import { register } from 'node:module';
import { pathToFileURL } from 'node:url';

register('ts-node/esm', pathToFileURL('./'));

Then use the --import flag to import the file.

NODE_OPTIONS="--import=./register.js" npx webpack configtest

Add to npm

"scripts": {
        "dev": "nodemon --watch src --ext ts --exec \"tsc --noemit && node --import=./src/dev/register.js src/app.ts\"",
}

@drernie
Copy link
Contributor Author

drernie commented Aug 25, 2024

if this benefits others, i advise to try tsx instead of ts-node. Either run directly tsx file.ts or with '--import', 'tsx' arguments.

@drernie drernie changed the title --experimental-loader may be removed Use tax Aug 25, 2024
@drernie drernie changed the title Use tax Use tsx Sep 20, 2024
@drernie drernie changed the title Use tsx Use tsx to avoid loader deprecation Sep 20, 2024
@drernie
Copy link
Contributor Author

drernie commented Jan 1, 2025

Obsoleted by #213

@drernie drernie closed this as completed Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant