Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

misakamayako
Copy link

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:

  • It uses the user's current Node.js version to dynamically determine the version of @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.
  • This approach is more flexible than using a fixed version, reducing the hassle of manually updating dependencies and improving the maintainability and stability of the project.

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}`
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@smeng9 smeng9 Nov 14, 2024

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?

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.

2 participants