Live data from Hacker News

Node.js is able to execute TypeScript files without additional configuration

nodejs.org

121–130 of 275 posts

Re: Node.js is able to execute TypeScript files without additional configuration

#121

I think this + node:test makes Node.js a pretty compelling sensible default for most things now. Running things with `tsx` was such a QoL improvement when it happened, but it didn't solve everything. Runtime type assertion at the edges is mostly solved through `zod` and tools like `ts-rest` and `trpc` makes it so much easier to do full-stack Typescript these days.

This. It's 2025 and the node ecosystem is finally usable by default! ESM modules just work with both Node and Typescript, Node can run .ts files, and there's the a good enough test runner built in. --watch. The better built in packages - `node:fs/promises` - are nice with top-level await for easier async loops. It took a while to convince everyone involved to just be pragmatic, but it's nice now.

What's the story with supporting CommonJS libraries? I've tried to update many projects to ESM multiple times over the years, and every time, I ended up backing out because it turned out that there was some important upstream library that was still CommonJS - or even if we fixed those issues, our downstream NPM consumers wouldn't be able to consume EJS. So then you have to go down this rabbit hole of dual compilation, which actually means using something other than tsc.

Re: Node.js is able to execute TypeScript files without additional configuration

#122
post #17
post #2

It looks like this works by stripping away the type information, so at best it saves you a transpilation pass and doesn't improve safety.

TypeScript never promised improving safety, maybe it’s a common misconception. But TypeScript has no runtime mode or information. You were always at the mercy of running and not ignoring the typechecker. Nothing stopped you from running ts-node or tsx on code with egregious type errors. TypeScript is more like a linter in that regard.

> TypeScript never promised improving safety

What, pray tell, would be the point of putting all that type information in there, and then have it checked (via tsc), if not for the sake of safety? What other use would this have in your opinion?

Re: Node.js is able to execute TypeScript files without additional configuration

#123
post #46

Earlier quoted context omitted.

>so at best it saves you a transpilation pass and doesn't improve safety. That's a bit misleading. Node being able to run TS code does not "improve safety", because that's not where the type checking happens. You can do type checking in your editor, or various other points in your toolchain. Node being able to run TS code reduces the friction in writing TS code, which indirectly helps with type safety.

Except it doesn't. In anything serious, you have to wait for a full type check to happen before you run your TS code. Why would you run code that has not been checked yet and could throw very weird errors like undefined property access? That just doesn't make sense. Yes, you can wait for your editor in your current open file, if you are lucky and the change in the open file doesn't break anything downstream in anothe…

You can tsc on the code and then ship that git hash if it passes. You don't need to run it every single time the code executes, nothing of value is gained, because nothing has changed.

Re: Node.js is able to execute TypeScript files without additional configuration

#124

I’m not a heavy JS/TS dev so here’s an honest question: why not use Bun and forget about node? Sure I understand that not every project is evergreen but isn’t Bun a much runtime in general? It supports TS execution from day 1, has much faster dependency resolution, better ergonomics… and I could keep going. I know I’m just a single data point but I’ve had a lot of success migrating old node projects to bun (in fact I…

I agree. I've tried the Node TS and test runner features, and they are still (not yet) as good as Bun's. So for now sticking with Bun for those.

Really, in the Node ecosystem you eventually learn not to put all your eggs in one basket. Different things excel in different aspects. Here is my preferred setup for now:

Bun.js: As a Node runtime, and for TS execution and test running. I tried lots: TSX, TS-Node, Node itself

NPM For executing tooling scripts

PNPM For installing dependencies. It's simply better than the rest (npm, yarn, bun) for several reasons

Biome.js For linting (superior to every other tool I tried)

Re: Node.js is able to execute TypeScript files without additional configuration

#125

It's not able to execute TypeScript, but a subset of it. The claim in the title is misleading if not totally wrong. This will unfortunately drive people towards using TS only as a linter, and not use its powerful features that are inherently impossible to implement with just type stripping.

I thought TS abandoned stuff that can't just be stripped. Besides enum, what do you use that isn't strippable?

Re: Node.js is able to execute TypeScript files without additional configuration

#126
post #48
post #36

Great, it does type stripping by replacing TypeScript with whitespace. Can it also now load ES5 modules? That way we can use them for everything.

> Can it also now load ES5 modules? ES5 standard (released in 2009) didn't have modules.

That answers it. I guess it still can’t! :-/

Re: Node.js is able to execute TypeScript files without additional configuration

#127
the js ecosystem is so sad.

all threads saying the truth, js on the server could implement actual ts and not yet another transpiler gets downvoted.

js "experts" think they are smarter because they know ts is just annotations for a linter. they don't even question why that is so and why that sucks.

Re: Node.js is able to execute TypeScript files without additional configuration

#129

I’m not a heavy JS/TS dev so here’s an honest question: why not use Bun and forget about node? Sure I understand that not every project is evergreen but isn’t Bun a much runtime in general? It supports TS execution from day 1, has much faster dependency resolution, better ergonomics… and I could keep going. I know I’m just a single data point but I’ve had a lot of success migrating old node projects to bun (in fact I…

> I’m not a heavy JS/TS dev so here’s an honest question: why not use Bun and forget about node?

Why would you switch from runtime A to runtime B? I mean, you presented no reason at all, let alone a compelling one, to pick either one. So what leads you to believe it is a reasonable idea to waste time switching runtimes?

Re: Node.js is able to execute TypeScript files without additional configuration

#130

https://github.com/nodejs/node/issues/57215 Not supporting type stripping in node_modules is unfortunate

But... that's like half the reason why I wanted this feature...

Writing a library in TypeScript (with typechecks in CI/CD as devDependencies) and just importing it directly from Node.js...

Post reply on HN