Skip to content

feat(create-vite): add @types/node to typescript templates#18642

Merged
bluwy merged 1 commit into
vitejs:mainfrom
smeng9:node-types
Sep 25, 2025
Merged

feat(create-vite): add @types/node to typescript templates#18642
bluwy merged 1 commit into
vitejs:mainfrom
smeng9:node-types

Conversation

@smeng9
Copy link
Copy Markdown
Contributor

@smeng9 smeng9 commented Nov 11, 2024

Closes #18600

@ArnaudBarre
Copy link
Copy Markdown
Member

If we go in that direction, I think we should also add types to node and app tsconfigs so that node types don't pollute default client code.
It also avoid the need for a vite-env.d.ts which IMO it's cleaner and what I do in my projects

@bluwy
Copy link
Copy Markdown
Member

bluwy commented Nov 12, 2024

Setting that has a different semantic to a separate file: https://www.typescriptlang.org/tsconfig/#types, so I'm not really sure if we should change that

@ArnaudBarre
Copy link
Copy Markdown
Member

Yeah I know it's different, but that the goal: you don't want to have process.env be ok for TS in the app files.

@smeng9
Copy link
Copy Markdown
Contributor Author

smeng9 commented Nov 12, 2024

you don't want to have process.env be ok for TS in the app files.

We do use a lot of process.env in our frontend code, particularly process.env.NODE_ENV == "development" to switch to a dev rest api url.

Vite also allows process.env in app files https://vite.dev/guide/env-and-mode#node-env-and-modes

@ArnaudBarre
Copy link
Copy Markdown
Member

While this is supported for compatibility with the ecosystem, Vite way of doing this is import.meta.DEV which avoid using a Node concept inside a code that will run in browser

@smeng9 smeng9 changed the title feat(create-vite): add @node/types to typescript templates feat(create-vite): add @types/node to typescript templates Dec 16, 2024
@bluwy
Copy link
Copy Markdown
Member

bluwy commented Sep 24, 2025

Since #20132 we have started using the types option instead, so we can go with what Arnaud propose and add "node" for the tsconfig.node.json file instead.

Would you like to update this PR with that, or open a new PR?

@smeng9
Copy link
Copy Markdown
Contributor Author

smeng9 commented Sep 25, 2025

Hi @bluwy ,

I have followed Arnaud's propose and added "node" for the tsconfig.node.json file.

Copy link
Copy Markdown
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks!

@bluwy bluwy merged commit 302f809 into vitejs:main Sep 25, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add @types/node as devDependency to all typescript templates

3 participants