How do I (recursively) update all dependencies with NPM?
My usual approach (using npm-check-updates
) is this:
ncu -u # updates my package.json to contain the newest versions of my dependencies
npm install # installs what ncu has written to package.json
npm update --depth 99999 # recursively updates packages to the newest version within the specified range
However, this does not work, and often leaves the dependencies in a state where npm audit
will complain about sub-dependencies. (Or, worse, npm update --depth 99999
sometimes hangs.)
Running npm audit fix
will update more packages, but only to fix security vulnerabilities.
The only true solution I've found is this:
rm -rf package-lock.json node_modules # remove any trace of the old packages
npm install # start fresh
…but this can't be the right solution, right? Right?
I'm surprised I have to ask this here, but reading the documentation and searching the internet for some time has only yielded npm update --depth 99999
and the npm-check-updates
package, which don't fully do the job.