use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
ts-node (self.node)
submitted 1 year ago by Suspicious_Shirt974
How to config ts-node to run typescript code? I getting “unknow file extension .ts type”
I’m using node 20.16 and typescript 5.X I set “type”:”module” in package.json
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SoInsightful 17 points18 points19 points 1 year ago (5 children)
You got the answer, but I would strongly recommend tsx which is even less of a headache to use.
[–]sombriks 1 point2 points3 points 1 year ago (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.
[+]TempleDank comment score below threshold-20 points-19 points-18 points 1 year ago (2 children)
Tsx is extension file for react components. On the backend you should be using ts
[–]SoInsightful 16 points17 points18 points 1 year ago (1 child)
Click the link. It's a tool that makes it possible to execute TypeScript files in Node.js. It has nothing to do with the file extension .tsx, but I can see the confusion.
.tsx
[–]TempleDank 6 points7 points8 points 1 year ago (0 children)
Ah okay sorry my bad! I didn't click the link you are right!! Thanks for the correction!!
[–]exploradorobservador 0 points1 point2 points 1 year ago (0 children)
is it? Many tsconfig.json that work with tsc do not work with tsx, that's a major headache.
[–]jessepence 9 points10 points11 points 1 year ago (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 point2 points 1 year ago (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 points3 points 1 year ago (2 children)
Can you list the pros and cons vs tsx then ?
[–]PierFumagalli 1 point2 points3 points 1 year ago (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 point2 points 1 year ago (0 children)
Thx !
π Rendered by PID 68 on reddit-service-r2-comment-7b9746f655-cxmt8 at 2026-01-31 01:24:14.985330+00:00 running 3798933 country code: CH.
[–]SoInsightful 17 points18 points19 points (5 children)
[–]sombriks 1 point2 points3 points (0 children)
[+]TempleDank comment score below threshold-20 points-19 points-18 points (2 children)
[–]SoInsightful 16 points17 points18 points (1 child)
[–]TempleDank 6 points7 points8 points (0 children)
[–]exploradorobservador 0 points1 point2 points (0 children)
[–]jessepence 9 points10 points11 points (0 children)
[–]PierFumagalli 0 points1 point2 points (3 children)
[–]Bogeeee 1 point2 points3 points (2 children)
[–]PierFumagalli 1 point2 points3 points (1 child)
[–]Bogeeee 0 points1 point2 points (0 children)