How do I fix a missing module in my package.json?

Issue

A Node.js build fails because of a missing module, which usually looks like:

Error: Cannot find module 'foo'

Resolution

You can automatically update your package.json to include a missing module with the --save --save-exact flags for npm. For example, if the 'foo' module is missing, and you want to use version 1.2.3:

$ npm install --save --save-exact foo@1.2.3
$ git commit -am 'track foo@1.2.3 in package.json'
$ git push heroku master

For more information, read our article on Troubleshooting untracked dependencies