I updated my Angular project with npm
and for some reason package.json
and package-lock.json
was not updated accordingly. So the question is, do I have to update them manually, or is there a way to update these files according to the actual versions in node_modules?
I tried npm init
but that gives me a very big package.json
containing every package in node_modules. Therefore I would prefer something that updates each entry in package.json
according to what is actually installed.
I had a similar problem, where not all of the needed modules in node_modules
were "required" (directly or indirectly) by package.json
, so every time I installed something using npm install
, it also removed a whole bunch of modules.
My solution wasn't a very satisfactory one, but it did the trick:
package-lock.json
file and package.json
files to keep them safe but out of the way.npm init
as you mentioned, to create a version of package.json
that contained all of the modules in node_modules
.node_modules
to something else to keep it safe but out of the way.package.json
file, again using npm init
, but which had no dependencies because there was now no node_modules
directory.require
statement, and did an npm --save install package@version
on each. I got the package name from the require
and then found it in the complete package.json
(from steps 2 and 3) and used the version number from that to ensure it matched what was there before. (I've got some legacy code with out-of-date modules, which is why I wanted specific versions.)package.json
file is minimal, but when I run npm install
, everything is up to date.