Enforcing node/npm versions during local development #50
Replies: 17 comments 2 replies
-
I can see the value in this. How would you imagine it working? Just a thought, have you considered using something like nave for this? (Nvm is more popular as version manager, but I imagine it might also be a bit harder to use as a devDependency in this way.) {
"name": "my-frontend-project-that-uses-node-v10",
"version": "1.2.3",
"scripts": {
"prepare": "nave use 10 node build-my-stuff.js"
},
"devDependencies": {
"nave": "^3.2.0"
}
} Of course, this will require that you have Bash installed in your dev environment. |
Beta Was this translation helpful? Give feedback.
-
Nave seems pretty cool, but we have a ton of teams that are already using nvm. To get them all to switch to using this wouldn't be possible, unfortunately. But I did find check-engine which checks if the developer has the proper node/npm version installed locally, but it uses the But glad that you think something like this will be useful! I'm thinking we can add something like a |
Beta Was this translation helpful? Give feedback.
-
There's no reason why people need to stop using nvm, or switch to nave full time. If it's a dev dep, and included in the When would |
Beta Was this translation helpful? Give feedback.
-
if your team is already using nvm, have you found/tried avn? it still doesn't enforce, but automates enough to make it harder to forget to use the correct version. i've found it to be very effective on my team. |
Beta Was this translation helpful? Give feedback.
-
I'm a bit unclear on the use case here - this is for an npm package that does not distribute a |
Beta Was this translation helpful? Give feedback.
-
Oh, another option is to add |
Beta Was this translation helpful? Give feedback.
-
oh wow, @isaacs I guess I never thought of that. That would essentially be the same thing as what I'm proposing and we don't need to add any new deps into our workflow! |
Beta Was this translation helpful? Give feedback.
-
@isaacs couple of questions though...
|
Beta Was this translation helpful? Give feedback.
-
npm modifies the If you put the I'm not sure why you'd list npm itself will still run with your global node. But the package scripts will run with the bundled node. The downside is that you need another copy of node in your project. If you have a lot of projects, that might get annoying. The |
Beta Was this translation helpful? Give feedback.
-
Yeah but I would like to enforce the node version and the npm version. If the global npm version would still be used when running npm run scripts, that wouldnt really solve the original issue right? |
Beta Was this translation helpful? Give feedback.
-
you could do something like this: {
"devDependencies": {
"nave": "3.2.0"
},
"scripts": {
"test": "nave use 12.11.0 npm run test-actual",
"test-actual": "do something"
}
} Since nave installs both node and npm, the |
Beta Was this translation helpful? Give feedback.
-
Yeah I could do that. But does it run when As for custom npm run scripts, i'd have to prefix every single command with nave. I appreciate the solution but just seems like more work and complicates things more than the workaround we're already doing. |
Beta Was this translation helpful? Give feedback.
-
Yeah, it'd really only be a solution for specific scripts that you'd want to be run with a given version of node/npm. It wouldn't change |
Beta Was this translation helpful? Give feedback.
-
Yeah, is a proposal for something like |
Beta Was this translation helpful? Give feedback.
-
Hi there, indeed being able to control Node.js/npm version is very handy. In any environment in fact, not just dev. Anytime Node.js/npm is used in my project I want the exact same versions to be used. For example, when a build happens in GitHub actions/Vercel/CI, I want a specific Node.js and npm version to be used. To control Node.js version, most build systems are now reading the .nvmrc file which is great. And requiring devs to use nvm is fine too as it's very common. To control npm versions I am not sure what is the solution besides adding Using Yarn you can do something like this:
When ran inside a project, it:
This is handy because it enforces which version will be used every time the command "yarn" (no matter its version) will be launched. Not saying we should do the same ( PS: Being able to control an npm version independently from the Node.js version is also very practical since new npm versions are published without new Node.js versions. And there are sometimes new npm features you want to use (like workspaces). |
Beta Was this translation helpful? Give feedback.
-
Can any of the contributors give an update on their position(s) on this? Would be great to know if this sounds feasible to the npm contributors or if there are any other ideas of how this can be implemented or resolved. Specifying an For instance, contributors of our projects tend to use either Node 14 or 16 recently. But 16 refactors the package-lock.json, so we need to enforce one of the two versions to prevent the lock file from bouncing back and forth, whenever new contributors open a PR after running |
Beta Was this translation helpful? Give feedback.
-
Since RFCs aren't a thing any more, i put up npm/cli#7253. What are your thoughts? |
Beta Was this translation helpful? Give feedback.
-
I've opened an npm issue in the community but is it worth exploring doing an RFC to enforce a node/npm version during local development only when working on client-side npm packages? Very frequently, client side packages only need to enforce versions locally since they usually distribute files that are transpiled for the browser.
We've tried using the npm engine-strict for this purpose but that enforces versions at the consumer level, which we don't want. As a workaround, we are stripping the
engines
field as a pre-publish step which solves the issue but this seems pretty hacky and I'm not sure what negative implications this may have.Beta Was this translation helpful? Give feedback.
All reactions