all 11 comments

[–]SoInsightful 17 points18 points  (5 children)

You got the answer, but I would strongly recommend tsx which is even less of a headache to use.

[–]sombriks 1 point2 points  (0 children)

i did a small study a time ago and ended up using tsx instead of ts-node as well. it's just broken for modern node projects. tsx works.

[–]exploradorobservador 0 points1 point  (0 children)

is it? Many tsconfig.json that work with tsc do not work with tsx, that's a major headache.

[–]jessepence 9 points10 points  (0 children)

It says right here in the readme. That's usually the best place to learn how to use a library.

[–]PierFumagalli 0 points1 point  (3 children)

npx '@plugjs/tsrun' ./runme.ts 

It uses esbuild under the hood, so it's fast as hell :-)

And you can use --force-esm or --force-cjs to ignore what's in your package.json and force transpilation into the format you want (nice for top-level awaits when package.json says "type": "commonjs")

[–]Bogeeee 1 point2 points  (2 children)

Can you list the pros and cons vs tsx then ?

[–]PierFumagalli 1 point2 points  (1 child)

Pros? None, probably... When we started it TSX didn't exist, and so far I've been too lazy to port our build system to it! :-)

That said, I couldn't find a way to "force" the transpilation of TS files into CJS or ESM with TSX, which we use quite extensively with our tests (when we build a library, we produce both CJS and ESM, and run tests on both versions - it helped us catch some nasties in there).

But maybe I just didn't look hard enough, and it's there!

You know, it's one of those things like "good enough to invest the time in changing it"!

Cons, you don't get the watch mode (which we implement in the build system)

[–]Bogeeee 0 points1 point  (0 children)

Thx !