"Cannot find module" in Node.js at runtime


Your Node.js app builds successfully but, when it's run, you get a "cannot find module" error like:

Error: Cannot find module 'foobar'


Yarn is better then npm at identifying missing modules, but both of them can make mistakes from time-to-time with existing node_modules directories.

First, you should temporarily disable any module caching:

$ heroku config:set NODE_MODULES_CACHE=false

Next, you should ensure that you aren't accidentally checking your modules into git.

Finally, you should check to ensure that your dependencies are correctly listed in package.json. Yarn does this automatically, but npm does not.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support
Terms of Service Privacy Cookies © 2018 Salesforce.com