Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save all the dependencies I install through npm into my package.json file?

I ran npm install for a lot of packages, but I forgot to include the --save argument. Now when I try to deploy on Heroku I get errors for missing certain dependencies. How can I automatically add those dependencies to my package.json file without doing npm install --save for each one?

like image 273
Jonathan Allen Grant Avatar asked Sep 24 '16 09:09

Jonathan Allen Grant


1 Answers

You can add all installed packages not installed with --save to your package.json automatically by calling npm init. It will append the dependencies to your existing ones. No settings in your file should be lost. Still don't forget to make a backup of the file to be 100% secure!

If the dependencies have not been appended, it can happen that just the merging failed:

  1. Backup your existing package.json in order to keep the dependencies you have in your package.json already and all the other settings. We need this file later again.

  2. Delete the package.json and run npm init in order to create a new package.json including the modules installed without --save in dependencies.

  3. Merge the dependencies of your newly created package.json into your old one manually. Restore your merged package.json.

like image 135
Michael Troger Avatar answered Oct 12 '22 23:10

Michael Troger