-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native Node.js Integration/Support #56838
Comments
I'm not sure what else @GeoffreyBooth is referring to here that doesn't already exist. |
That’s an exposed endpoint for other tools to consume. To actually run a TypeScript file, such as the example’s Or to put it another way, look at the functionality added by Another thing that would be very helpful coming from the TypeScript team is a strong recommendation for |
What you're describing is
As for writing the official hooks ourselves, that's a scoping decision for us, not a technical blocker (as evidenced by other runtimes which are supporting TS out of the box - it's clearly possible without TS shipping components it doesn't already). Daniel and I will discuss more when we're both back from the holidays, but it's obviously not an easy thing to just commit to.
We have some new docs on this (link to a section of a much larger guide to modules in general) https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-compiling-and-running-the-outputs-in-nodejs . I'd like to figure out more ways to get this set of docs in particular in front of people's faces -- they're very comprehensive and answer virtually every question people have come to us with, but the area is famously hard to understand and I'm not sure how to get more people to see this content. |
In April 2023 Node did some user research, available at https://github.com/nodejs/next-10/blob/main/surveys/2023-04/Node.js%20Survey%20open%20ended%20answers.pdf. The last question was “Do you have any recurring issues when using Node.js?” and was free response. Of the 325 responses we received, 27% referred to ESM or modules (details). Half of those, or 13% of all responses, mentioned types or TypeScript.
So we know that this is a major challenge for a large portion of Node users. It’s so difficult that Deno and Bun advertise “out-of-the-box TypeScript” as a major selling point. We get very strongly worded feedback like this:
So clearly there is a lot of room for improvement around the UX of this. Education is a part of it, and a reasonable place to start, but I think this is far too difficult for far too many people to just write better docs and consider that good enough. A particularly difficult use case that comes up often is one where an existing app that is compiled into CommonJS needs to switch to compile into ESM because the developer wants to add an ESM-only dependency. This seems to often set off a game of whack-a-mole, where changing one setting makes Node work but the bundler fail, or the bundler work but the test runner fail, and so on. There are just too many |
If When I read https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax, there’s a lot of text written about how this simplifies TypeScript knowing when to skip emitting imports for types, but then in the last paragraph it mentions almost as an aside:
This “what you write is what you get” feels like it would solve a lot of problems? A big frustration that people have is trying to figure out how to get TypeScript to output real ESM syntax. If TypeScript’s default behavior was to output code as written and never convert module formats ( |
I'm surprised I can't use
I ended up with |
🔍 Search Terms
native nodejs integration
nodejs support
nodejs integration
run nodejs
✅ Viability Checklist
⭐ Suggestion
I would like Node.js and Typescript to support the following user experience.
$ node script.ts "Hello World"
This setup requires a seamless integration between Node.js and the TypeScript language. The @nodejs community has a longstanding issue documented here regarding this specific use case. While the majority of the work is anticipated to take place within the Node.js runtime, establishing an effective communication channel between the Node.js and TypeScript communities is crucial for tracking and progressing this feature request. It appears that the Node.js community could benefit from collaboration and support from the TypeScript community, as mentioned in this comment.
📃 Motivating Example
The TypeScript ecosystem is closely integrated with Node.js. It would be fantastic if Node.js could effortlessly consume TypeScript code without the need for additional third-party tools. Both Deno and Bun runtimes have independently implemented this feature. However, Node.js currently lags behind in providing native support for this capability.
💻 Use Cases
.d.ts
and.js
files in non-browser environments.What shortcomings exist with current approaches?
Additional tooling is required, and there are no defined heuristics.
What workarounds are you using in the meantime?
Currently, tools such as ts-node or tsx are employed to execute TypeScript code directly in the Node.js ecosystem. Alternatively, developers may opt for alternative runtimes like Deno and Bun.
The text was updated successfully, but these errors were encountered: