How do I update devDependencies in NPM? - node.js

npm update seems to just update the packages in dependencies, but what about devDependencies.
Right now you can install devDependencies by running npm install ., but this doesn't work for npm update .
Any ideas?

To update package.json in addition to the local modules, run
npm update --save-dev
Alternatively, the same command to save time
npm update -D
You can view the full detail of update, or any command for that matter through
npm help <cmd>

Install npm-check-updates (https://www.npmjs.org/package/npm-check-updates), then jump into your project folder and run:
npm-check-updates
And to update and save changes to your package.json file:
npm-check-updates -u

These steps worked for me :
npm install -g npm-check-updates
ncu -u
npm update
npm install

npm outdated - for an overview what's outdated
npm install -g npm-check-updates - as pointed correctly by Michael
ncu -u - it'll automatically update all dependencies (also dependencies, i.e., it's of course different than devDependencies) versions in package.json, without reinstalling it yet. It'll just change the "numbers" in package.json
npm update - actual dependencies installation
(Optional, depending by scenario) you might need to use the flag --force, or (new in NPM v7) --legacy-peer-deps to complete the process. You can read about difference between those 2 on What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?
(Optional) you can validate it using ncu -u and for correctly updated dependencies you should see the text All dependencies match the latest package versions :)

This problem does no longer excise with the current version of NPM (1.3.11).
Update works fine with: npm update

If you are using outdated npm version it might be the problem. So before any other commands execute:
sudo npm install npm -g
or (if above doesn't work):
sudo npm update npm -g
Then relaunch the console (in order for changes to take effect).
Now you can check your new npm --version and if it is up to date execute:
npm update
or (if you prefer):
npm update --save-dev

I ran into the same problem as OP had, and found no solution, so I decided to write a Grunt plugin that will auto-update my devDependencies..
It's on Github, I'd love to get some input and collaborations in order to make it the best tool that NPM hasn't provided.
Basically it will auto-update your outdated development dependencies with a simple Grunt Task.
https://github.com/pgilad/grunt-dev-update

What worked for me is installing individual dev dependencies like this
npm install react-test-renderer#15.6.1 --save --only=dev

i found the answer onhttps://nodejs.dev/learn/update-all-the-nodejs-dependencies-to-their-latest-version and this is working for me for all the major release as well
npm install -g npm-check-updates
ncu -u
npm update
to check the outdated package use
npm outdated

One (slow) way to do force the update, is to remove the node_modules directory, and then do npm install again.
This was a known bug of the npm update command, which has been fixed on the development branch of npm, see here:
https://github.com/isaacs/npm/pull/3863
It should land on the latest stable version of npm pretty soon.

Related

Not able to install express via npm [duplicate]

When creating a new Angular 5 project:
node version: 8.9.2
npm version: 5.5.1
My Command is:
npm install -g #angular/cli
The Error is:
npm ERR! **Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'**
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log
The error log is here
This solved it for me:
Open Windows Powershell as admin
npm cache clean --force
npm install -g #angular/cli
https://devblogs.microsoft.com/premier-developer/getting-started-with-node-js-angular-and-visual-studio-code/
Solution:
npm cache clean --force
then try again to create your app (here when creating a react app) or install what you were about to install.
create-react-app myproject
(creating react app)[same npm problem that can occur in different operation]
npm install -g #angular/cli#latest
(installing angular cli (or installing anything else))
It will work.
explanation:
That's a problem related to npm, it's about the cache that get corrupt. Even though in newer versions of npm they implemented self healing, which normally guarantee no corruption, but it seem it's not that efficient.
Forcing clean cache resolve the problem.
The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux) and %AppData%/npm-cache (windows). For my current npm version and when i checked, there was three directories.
if you check the first or the second, the structure is as follow
And each cache file have a json format (and that what get parsed)
Here a good link from the doc: https://docs.npmjs.com/cli/cache
[Update] Also if it happen that this didn't solve it, you may check this answer here https://stackoverflow.com/a/50191315/7668448 it show how you can change the npm registry, that can be helpful. Check and see.
If
npm cache clean --force
doesn't work.
try
npm cache clean --force
npm update
Npm uses Cache for downloading new packages for you.
You need to clear your npm cache.
use following command to clean :
npm cache clean --force
then normally use your npm install command
e.g.
npm install -g #angular/cli
I solve that with
npm cache clean --force
then update npm
npm i npm#latest -g
then normally use your npm install command
npm install
delete npm and npm-cache folders in C:\Users\admin\AppData\Roaming\ (windows)
then execute cmd
npm cache clear --force
npm cache verify
update npm to latest version
npm i -g npm
then create your project
1)Angular
npm i -g #angular/cli#latest
ng new HelloWorld
2)React
npm i -g create-react-app
create-react-app react-app
None of the 30 answers here worked for me. I needed to:
delete node_modules and package-lock.json
npm cache clean --force
npm install -g #angular/cli
npm i --package-lock-only
npm ci
Phew!
this solved it npm cache clean --force
Simple solutions:
npm cache clean --force
npm install
This command alone solved my problem:
npm cache clean --force
Also you should make sure you are using the correct version of node.
Using nvm to manage the node version:
nvm list; # check your local versions;
nvm install 10.10.0; # install a new remote version;
nvm alias default 10.10.0; # set the 10.10.0 as the default node version, but you have to restart the terminal to make it take effect;
I use Windows and removed all the files that were listed below and my problem was solved
C:\Users{{your-username}}\AppData\Roaming\npm-cache
npm cache clean --force worked for me
Error Resolved :
$ npm install -g gulp
npm WARN deprecated gulp-util#3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm ERR! Unexpected end of JSON input while parsing near '.../RGs88STtAtiMP3tCiNdU'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\admin\AppData\Roaming\npm-cache_logs\2018-11-20T07_38_56_733Z-debug.log
Solution
npm cache clean --force
For Windows : go to C:\Users\username\AppData\Roaming\npm-cache
Delete all files and run
npm install && npm start
I solved that by first cleaning the cache using
npm cache clean --force
Then
npm install -g #angular/cli
My case - Windows 7 (had nothing better at the needed moment).
Helped me the following:
Deleting everything from C:\Users\username\AppData\Roaming\npm-cache
AND
Deleting package-lock.json
I resolved my problem with this one liner
npm cache clean --force
Note: since its a clean install, I had no concerns emptying npm cache.
ERROR: npm ERR! Unexpected end of JSON input while parsing near '...ore-js":"3.0.0-beta.1
This occurs when installing the expo CLI globally, This works for me!
npm cache clean --force
I got error (file already exists --force to overwrite) after running the following code:
npm cache clean --force
npm install -g #angular/cli
I solved it using :
npm i -g --force npm
Make sure to run the first commands to flush the cache of npm.
It's error from your npm....
So unistall node and install it again.
It works....
PS: After installing node again, install angular cli globally.
npm install -g #angular/cli#latest
I solve that with
First delete package-lock.json
npm cache clean --force
then update npm
npm i npm#latest -g
then use npm install command
npm install
If you looking for npm install and getting same kind of error
Delete package-lock.json and npm cache clean --force and try
In my case I changed the network to a much stronger one and npm install worked perfectly:
npm cache clean --force
If npm cache clean --force doesn't resolve the issue, try deleting the ~/.npm directory (*nix/macOS). This is the directory where node stores its cache, locks, logs, global packages (unless you're using nvm), and modules installed via npx.
First, backup your current ~/.npm directory:
mv ~/.npm ~/.npm-backup
Now try running your npm command again. This will create a new ~/.npm directory. If the issue is resolved, you can safely remove you backup. Before doing so, you may want to review the global packages installed in your ~/.npm-backup directory so you can reinstall them using npm i -g [package].
rm -rf ~/.npm-backup
If the issue is not resolved, you can restore your backup:
rm -rf ~/.npm
mv ~/.npm-backup ~/.npm
Careful with those rm commands, folks!
Instead of clearing the cache you can set a temporary folder:
npm install --cache /tmp/empty-cache
or
npm install --global --cache /tmp/empty-cache
As of npm#5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use npm cache verify instead. On the other hand, if you're debugging an issue with the installer, you can use npm install --cache /tmp/empty-cache to use a temporary cache instead of nuking the actual one.
For me I had to clone my branch again and do npm install
You can use yarn package manager instead of npm.
It solved this problem for me
I've faced this issue and I tried all the answers on Stackoverflow but not worked for me, finally I found solution for this issue:
First of all you have to uninstall nodejs and remove all the files related him
Go to "Register Editor" and search for all "nodejs", "node.js" and delete them
Restart your computer
And reinstall nodejs then install angular.
It's worked for me
These commands worked for me
sudo npm cache clean --force
sudo npm cache verify
sudo npm i npm#latest -g
Try setting
npm config set strict-ssl false
and then try running,
npm install -g #angular/cli
This happens something due to cache or outdated version of Node Package Manager
i just updated my NPM it works fine
here is command to update Npm to latest version
npm i npm#latest -g
after updating NPM run your desired command

gulp 4.0.0 shows npm outdated

I am running the latest available Gulp.js 4.0.0 and yet somehow npm says this:
> npm outdated
Package Current Wanted Latest Location
gulp 4.0.0 4.0.0 3.9.1
To solve the issue I have done:
npm update
npm update -g
remove node_modules and run npm install lependu answer
remove node_modules, npm cache clean -f and run npm install lependu answer
Is there a way to fix this?
npm had some issues with publication of new packages this week and the week before too. See this So I guess an npm cache clean -f would help. If not, you can do nothing more, than wait.

NPM Install Error:Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'

When creating a new Angular 5 project:
node version: 8.9.2
npm version: 5.5.1
My Command is:
npm install -g #angular/cli
The Error is:
npm ERR! **Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'**
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log
The error log is here
This solved it for me:
Open Windows Powershell as admin
npm cache clean --force
npm install -g #angular/cli
https://devblogs.microsoft.com/premier-developer/getting-started-with-node-js-angular-and-visual-studio-code/
Solution:
npm cache clean --force
then try again to create your app (here when creating a react app) or install what you were about to install.
create-react-app myproject
(creating react app)[same npm problem that can occur in different operation]
npm install -g #angular/cli#latest
(installing angular cli (or installing anything else))
It will work.
explanation:
That's a problem related to npm, it's about the cache that get corrupt. Even though in newer versions of npm they implemented self healing, which normally guarantee no corruption, but it seem it's not that efficient.
Forcing clean cache resolve the problem.
The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux) and %AppData%/npm-cache (windows). For my current npm version and when i checked, there was three directories.
if you check the first or the second, the structure is as follow
And each cache file have a json format (and that what get parsed)
Here a good link from the doc: https://docs.npmjs.com/cli/cache
[Update] Also if it happen that this didn't solve it, you may check this answer here https://stackoverflow.com/a/50191315/7668448 it show how you can change the npm registry, that can be helpful. Check and see.
If
npm cache clean --force
doesn't work.
try
npm cache clean --force
npm update
Npm uses Cache for downloading new packages for you.
You need to clear your npm cache.
use following command to clean :
npm cache clean --force
then normally use your npm install command
e.g.
npm install -g #angular/cli
I solve that with
npm cache clean --force
then update npm
npm i npm#latest -g
then normally use your npm install command
npm install
delete npm and npm-cache folders in C:\Users\admin\AppData\Roaming\ (windows)
then execute cmd
npm cache clear --force
npm cache verify
update npm to latest version
npm i -g npm
then create your project
1)Angular
npm i -g #angular/cli#latest
ng new HelloWorld
2)React
npm i -g create-react-app
create-react-app react-app
None of the 30 answers here worked for me. I needed to:
delete node_modules and package-lock.json
npm cache clean --force
npm install -g #angular/cli
npm i --package-lock-only
npm ci
Phew!
this solved it npm cache clean --force
Simple solutions:
npm cache clean --force
npm install
This command alone solved my problem:
npm cache clean --force
Also you should make sure you are using the correct version of node.
Using nvm to manage the node version:
nvm list; # check your local versions;
nvm install 10.10.0; # install a new remote version;
nvm alias default 10.10.0; # set the 10.10.0 as the default node version, but you have to restart the terminal to make it take effect;
I use Windows and removed all the files that were listed below and my problem was solved
C:\Users{{your-username}}\AppData\Roaming\npm-cache
npm cache clean --force worked for me
Error Resolved :
$ npm install -g gulp
npm WARN deprecated gulp-util#3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm ERR! Unexpected end of JSON input while parsing near '.../RGs88STtAtiMP3tCiNdU'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\admin\AppData\Roaming\npm-cache_logs\2018-11-20T07_38_56_733Z-debug.log
Solution
npm cache clean --force
For Windows : go to C:\Users\username\AppData\Roaming\npm-cache
Delete all files and run
npm install && npm start
I solved that by first cleaning the cache using
npm cache clean --force
Then
npm install -g #angular/cli
My case - Windows 7 (had nothing better at the needed moment).
Helped me the following:
Deleting everything from C:\Users\username\AppData\Roaming\npm-cache
AND
Deleting package-lock.json
I resolved my problem with this one liner
npm cache clean --force
Note: since its a clean install, I had no concerns emptying npm cache.
ERROR: npm ERR! Unexpected end of JSON input while parsing near '...ore-js":"3.0.0-beta.1
This occurs when installing the expo CLI globally, This works for me!
npm cache clean --force
I got error (file already exists --force to overwrite) after running the following code:
npm cache clean --force
npm install -g #angular/cli
I solved it using :
npm i -g --force npm
Make sure to run the first commands to flush the cache of npm.
It's error from your npm....
So unistall node and install it again.
It works....
PS: After installing node again, install angular cli globally.
npm install -g #angular/cli#latest
I solve that with
First delete package-lock.json
npm cache clean --force
then update npm
npm i npm#latest -g
then use npm install command
npm install
If you looking for npm install and getting same kind of error
Delete package-lock.json and npm cache clean --force and try
In my case I changed the network to a much stronger one and npm install worked perfectly:
npm cache clean --force
If npm cache clean --force doesn't resolve the issue, try deleting the ~/.npm directory (*nix/macOS). This is the directory where node stores its cache, locks, logs, global packages (unless you're using nvm), and modules installed via npx.
First, backup your current ~/.npm directory:
mv ~/.npm ~/.npm-backup
Now try running your npm command again. This will create a new ~/.npm directory. If the issue is resolved, you can safely remove you backup. Before doing so, you may want to review the global packages installed in your ~/.npm-backup directory so you can reinstall them using npm i -g [package].
rm -rf ~/.npm-backup
If the issue is not resolved, you can restore your backup:
rm -rf ~/.npm
mv ~/.npm-backup ~/.npm
Careful with those rm commands, folks!
Instead of clearing the cache you can set a temporary folder:
npm install --cache /tmp/empty-cache
or
npm install --global --cache /tmp/empty-cache
As of npm#5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use npm cache verify instead. On the other hand, if you're debugging an issue with the installer, you can use npm install --cache /tmp/empty-cache to use a temporary cache instead of nuking the actual one.
For me I had to clone my branch again and do npm install
You can use yarn package manager instead of npm.
It solved this problem for me
I've faced this issue and I tried all the answers on Stackoverflow but not worked for me, finally I found solution for this issue:
First of all you have to uninstall nodejs and remove all the files related him
Go to "Register Editor" and search for all "nodejs", "node.js" and delete them
Restart your computer
And reinstall nodejs then install angular.
It's worked for me
These commands worked for me
sudo npm cache clean --force
sudo npm cache verify
sudo npm i npm#latest -g
Try setting
npm config set strict-ssl false
and then try running,
npm install -g #angular/cli
This happens something due to cache or outdated version of Node Package Manager
i just updated my NPM it works fine
here is command to update Npm to latest version
npm i npm#latest -g
after updating NPM run your desired command

How to shrinkwrap devDependencies, but not install them unless necessary?

I have a bunch of devDependencies needed in order to run test suite and have production dependencies locked down with npm shrinkwrap. The problem is that when I run npm install, only production dependencies are installed, in order to install devDependencies, I have to remove npm-shrinkwrap.json and run it again.
Now if shrinkwrap contains devDependencies as well, they get installed in production, where they are not required. Surely there should be some command line arguments to force only normal dependencies to be installed?
September, 2016:
As others have mentioned as well, there were some huge efforts to enhance the shrinkwrap feature starting with npm v3.10.8.
Thanks to this, it'll be possible to keep your devDependencies locked while installing only the production dependencies:
npm shrinkwrap --dev
npm install --only=prod
2013 answer:
As stated in the NPM docs:
Since npm shrinkwrap is intended to lock down your dependencies for
production use, devDependencies will not be included unless you
explicitly set the --dev flag when you run npm shrinkwrap. If
installed devDependencies are excluded, then npm will print a warning.
If you want them to be installed with your module by default, please
consider adding them to dependencies instead.
Basically, or you lock down all deps, or only the production deps.
Not even running npm install --dev or npm install --force can transcend the shrinkwrap functionality.
It looks like this feature was recently added in v3.3 of the npm client per the changelog
You'll now be able to run npm install --only=prod to achieve the effect you wish.
EDIT 2016/09/13
I've tested out npm v3.10.8, and this functionality now works as expected. We've shrinkwrapped our devDependencies and can install only prod dependencies when we deploy.
I think it's worth mentioning that this feature should start working as expected very soon. According to this github issue, tons of people were running into the same problem, and according to this pull request, it will be in the next release (scheduled for 2016-09-08).
With the pull request merged in, all you would have to do is:
npm i --only=prod
As to npm 5 (I've tried on 5.5.1 and 5.6.0), --production (--only=prod) flag is problematic.
When package-lock.json exists in the folder,
npm shrinkwrap --production
simply changes the file name to npm-shrinkwrap.json.
How I managed to solve this issue is to run:
npm prune --production
and then run:
npm shrinkwrap --production
This is fixed in npm 3.10.8; npm install --production shouldn't install dev deps in a shrinkwrap created by npm shrinkwrap --dev: https://github.com/npm/npm/releases/tag/v3.10.8

How to install a previous exact version of a NPM package?

I used nvm to download node v0.4.10 and installed npm to work with that version of node.
I am trying to install express using
npm install express -g
and I get an error that express requires node version >= 0.5.0.
Well, this is odd, since I am following the directions for a node+express+mongodb tutorial here that used node v0.4.10, so I am assuming express is/was available to node v0.4.10. If my assumption is correct, how do I tell npm to fetch a version that would work with my setup?
If you have to install an older version of a package, just specify it
npm install <package>#<version>
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view <package> versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
It's quite easy. Just write this, for example:
npm install -g npm#4.6.1
Or:
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
First remove old version, then run literally the following:
npm install express#3.X
or
npm install express#4.X
and for stable or recent
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
In my opinion that is easiest and fastest way:
$ npm -v
4.2.0
$ npm install -g npm#latest-3
...
$ npm -v
3.10.10
you can update your npm package by using this command:
npm install <package_name>#<version_number>
example:
npm install yargs#12.0.2
You can use the following command to install a previous version of an npm package:
npm install packagename#version
I have a general way to solve this type of problems, which could be helpful too, especially when cloning repositories to run them locally, but requires a little more analysis of the versions.
With the package npm-check-updates I verify the versions of the packages (according to the package.json file) that are not declared in their latest available versions, as shown in the figure (https://www.npmjs.com/package/npm-check-updates):
With this information we can verify the update status of the different packages and make decisions as to which packages to upgrade / degrade and which ones do not.
Assuming that we decided to update all the packages as they are listed, we can use the ncu -u command which only modifies your package.json file. Run npm install to update your installed packages and package-lock.json.
Then, depending on the requirements of the repository, we can refine what is needed, installing the specific versions with
npm view <package> versions and npm install <package>#<version>
The easiest way I found: add package name with the version in package.json and then run npm install
"next-seo": "^5.4.0",
"next-themes": "^0.1.1",
"nextjs-progressbar": "^0.0.14",
If you have to install an older version of a package, just specify it
npm install #
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
Use npm config set save-exact=true if you want to install the exact version

Resources