-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
chore(create-vite): add @types/node as devDependency in *-ts #18653
base: main
Are you sure you want to change the base?
Conversation
packages/create-vite/src/index.ts
Outdated
write('package.json', JSON.stringify(pkg, null, 2) + '\n') | ||
if (template.endsWith('-ts')) { | ||
if (!pkg.devDependencies) pkg.devDependencies = {} | ||
pkg.devDependencies['@types/node'] = `^${process.versions.node}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.versions.node may not match the version of @types/node published on npm
For example, odd numbers of versions are not available on npmjs, only even numbers of version are available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder. You're right, I overlooked this point. Moving forward, I will consider automatically adding @types/node only when the user's Node version meets Vite's requirements and is an even-numbered version. Otherwise, I'll output a prompt in the console. This might be a more refined solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this still has issue. For example, at the time of writing this post, the latest node on https://nodejs.org/en is 22.11.0, but the latest @types/node on https://www.npmjs.com/package/@types/node?activeTab=versions is 22.9.0 . This will cause a mismatch and the package cannot be resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we probably have to use npm's api to fetch all available versions and pick the most suitable version in a range?
fix(#18600): use user’s Node version for @types/node version instead of fixed version
This PR resolves the issue #18600 and improves upon the previous PR #18642:
@types/node
, instead of using a fixed version. This improvement ensures that the@types/node
version matches the Node.js version the user is actually using, avoiding potential compatibility issues.