News for hackers. Stuff that matters.
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by rickcarlino on Tuesday November 21, 2023 @05:34AM (#38361864)
I’ve found TSX to be a better alternative to ts-node. It seems to have more sensible defaults in 2023. https://github.com/privatenumber/tsx
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by herpdyderp on Tuesday November 21, 2023 @07:54AM (#38363022)
Tsx is great but doesn’t work in all situations unfortunately. Some broken cases that I remember off the top of my head are Playwright and test coverage.
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by privatenumber on Tuesday November 21, 2023 @08:49AM (#38363543)
Maintainer of tsx here.

tsx should be able to handle Playwright as of v4+, and hopefully the test coverage you're referring to.

Before, it was compiling ESM syntax to CJS as an effort to ease the ecosystem's CJS -> ESM migration, and hiccuping whenever it encountered `eval()`. Now it includes smarter checks to determine if a file needs to be compiled at all and skips processing most dependencies.

Hope it works well for you!

Re:Finally, a guide for Node.js and TypeScript and ESM that ... by herpdyderp on Tuesday November 21, 2023 @11:06AM (#38365505)
I see v4 was published just 12 days ago. I'll have to give it another shot! Thanks!
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by e1g on Tuesday November 21, 2023 @09:54AM (#38364400)
Can confirm we use tsx with playwright with no issues. Thanks!
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by domh on Tuesday November 21, 2023 @07:10AM (#38362562)
I use node-dev which seems to have good ts support. node-dev with --respawn is a good cheap way to watch and rerun ts files on change!
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by lloydatkinson on Tuesday November 21, 2023 @05:52AM (#38361982)
I was about to say exactly this. If you’re writing Node scripts there’s no reason to use ts-node as tsx, by default, does the correct thing and works correctly with ES modules.

Of course, Deno offers a better experience for scripts or programs.

Re:Finally, a guide for Node.js and TypeScript and ESM that ... by khalidx on Tuesday November 21, 2023 @06:29AM (#38362252)
I tried `tsx` but it didn't work for some reason (can't remember why right now). Also, if you've been using `ts-node` and feel comfortable with it, this setup should work for you instead of switching your toolchain.
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by privatenumber on Tuesday November 21, 2023 @08:51AM (#38363568)
tsx v4 was released a couple weeks ago which addressed many incompatibility issues. Hope you have a chance to give it another shot :)
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by khalidx on Tuesday November 21, 2023 @09:33PM (#38373919)
I definitely will!
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by vmfunction on Tuesday November 21, 2023 @07:05AM (#38362529)
or esno, which is tsx with esbuild.
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by lhnz on Tuesday November 21, 2023 @07:09AM (#38362553)
I'm using `esyes` [0] by Yehuda Katz and the logic is simple and it works very well.

[0] https://github.com/starbeamjs/esyes

Re:Finally, a guide for Node.js and TypeScript and ESM that ... by vmfunction on Tuesday November 21, 2023 @07:13AM (#38362594)
thanks for sharing! Didn't know about this one.
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by madeofpalk on Tuesday November 21, 2023 @09:50AM (#38364343)
tsx is "tsx with esbuild" though?
Re:Finally, a guide for Node.js and TypeScript and ESM that ... by bruh2 on Tuesday November 21, 2023 @09:14AM (#38363857)
Love this project, used it quite a bit. However I always opt for using esno[1] instead, merely because of the name; having two tools share the same name throws me off.

[1] https://github.com/esbuild-kit/esno

Re:Finally, a guide for Node.js and TypeScript and ESM that ... by madeofpalk on Tuesday November 21, 2023 @10:00AM (#38364493)
> From v0.15, esno is essentially an alias of tsx

heh. It really is https://github.com/esbuild-kit/esno/blob/master/esno.js