Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku missing module

I'm trying to deploy a simple node.js server to Heroku, but keep running into this error:

Error: Cannot find module 'morgan'

I'm using morgan to do some HTTP logging, i have morgan in my package.json under the devDependencies (along with many others)

"devDependencies": {
    "morgan": "~1.5.0"
}

I can do npm install locally and start the server without any issues, but when I deploy to Heroku I keep running into that error once it starts the server.

Is there anything I'm forgetting?

like image 307
woutr_be Avatar asked Mar 03 '26 18:03

woutr_be


1 Answers

By default Heroku execute npm install --production which avoid install devDependencies, quoting literally documentation of Heroku.

The Heroku node buildpack runs npm install --production, which doesn’t install devDependencies in your package.json file. If you wish to install development dependencies when deploying to Heroku, you should move your build dependencies (such as grunt plugins) from devDependencies to dependencies in package.json.

If you use the Morgan module, you need move it to 'dependencies'.

Source: https://devcenter.heroku.com/articles/nodejs-support

like image 186
Deoxyseia Avatar answered Mar 05 '26 09:03

Deoxyseia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!