Reputation: 100020
Using package.json and NPM how can I install, using the command line, the highest number of major version 1 or major version 2?
In this case, I want to downgrade a package from version 2.x.x to 1.x.x. And this case, I want x to be the biggest number possible.
Something like:
npm install foo@latest:1
I am not sure. My end goal is to get the right data into package.json, such that I never jump to version 2.0.0, and always remain at the highest 1.x.x version.
Is there something I can manually insert into package.json? then run npm install foo
?
Unfortunately the NPM article on semver is not helping much.
Upvotes: 5
Views: 3746
Reputation: 5930
If you want to do that manually:
npm install <package-name>@^xx
e.g. npm install react@^18 will install the latest minor version of major version 18.
Upvotes: 4
Reputation: 19268
If you're wanting to always pick the latest and greatest for a particular version but not wanting to jump major version then you can use the ^
prefix in the package.json.
Example:
"dependencies": {
"nodemailer": "^2.3.2"
},
Note: The latest major release for nodemailer is version 4
.
This will resolves to [email protected]
, which is the last release for version 2
.
Doing npm install
produces the following
Output:
npm WARN deprecated [email protected]: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated [email protected]: the module is now available as 'css-select'
npm WARN deprecated [email protected]: the module is now available as 'css-what'
[email protected] node_modules/nodemailer
Reference: http://fredkschott.com/post/2014/02/npm-no-longer-defaults-to-tildes/
Upvotes: 5