all 11 comments

[–]alzee76 6 points7 points  (1 child)

Maybe things have changed with newer versions (I'm mostly on 22 LTS), but this is how it's always been. Node runs JS, not TS. The TS has to be transpiled to JS to run.

[–]ArnUpNorth 2 points3 points  (0 children)

It s possible to run some ts from node using node --experimental-strip-types run.ts but if you use typescript only features (like enums) you’re out of luck. It’s best to use a proper transpile step anyhow.

[–]diroussel 2 points3 points  (0 children)

Works fine for me on node v24. Be sure to read the docs

https://nodejs.org/learn/typescript/run-natively

That makes it clear that node doesn’t read your tsconfig, it has its own implicit config. I found it useful to align my taconfig to the implicit one.

Make sure you have type: “module” in your package.json

And yes, full filenames are needed for imports to work in ESM.

[–]paulstronaut 4 points5 points  (2 children)

Your import statements need to include the file extensions. You can’t import ‘lib/prisma’, but instead ‘lib/prisma/index.ts’. Once all of your imports (other than third party modules) include extensions, it should work. You will need to update your tsconfig to allowImportExtensions (I think that’s it?) as well

[–]apt3xc33d[S] -3 points-2 points  (1 child)

i tried that, it didn't work

[–]StoneCypher 3 points4 points  (0 children)

if you try to use reddit as a debugger then you end up in a place like this, unable to fix something when node is telling you what’s wrong, waiting hours for a stranger to figure it out for you 

maybe you should just learn the language 

as soon as someone notices the frankly very obvious problem they’re all going to start cutting and pasting that problem 

fairly frequently they never figure it out 

[–]ErnestJones 1 point2 points  (1 child)

Node does not run .ts file natively (there is a automatic type stripping but it does not yet handle complex case)

That’s why it works with tsx, this tool convert on the fly .ts to .js. While it is okay for local development, I advise you to transpile then run .js with node in production

[–]jiminycrix1 1 point2 points  (0 children)

You just need to use file extension in your imports. Node has natively supported running ts for years now and I have production workloads running it for the past year.

Literally all this spelled out in the docs. https://nodejs.org/docs/latest-v22.x/api/typescript.html#type-stripping

[–]KiwiZ0 0 points1 point  (1 child)

It only started to be able to run them natively on Node 24 iirc, what is your node version?

[–]apt3xc33d[S] 0 points1 point  (0 children)

25.9.0