I keep receiving this error: "Error: Cannot find module 'models'" on Heroku. I'm using Node.JS. I'm using this Node.JS project .
I copied out the logs from Heroku and put them in a gist due to length.
Here's an excerpt:
2013-08-27T12:56:27.792568+00:00 app[web.1]: module.js:340
2013-08-27T12:56:27.791930+00:00 app[web.1]:
2013-08-27T12:56:27.792873+00:00 app[web.1]: throw err;
2013-08-27T12:56:27.792873+00:00 app[web.1]: ^
2013-08-27T12:56:27.794658+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2013-08-27T12:56:27.794658+00:00 app[web.1]: Error: Cannot find module 'models'
I setup my configs on Heroku and have a mongolab mongodb setup and the config val MONGO_URL is setup and the NODE_ENV is set to production.
You can find the site here .
Does anyone know what's going on? Thank you for your help!
You need to set NODE_PATH=lib
to heroku's configuration variables.
NODE_PATH
tells node where to find modules besides node_modules
directory.
Also, you need to tell the app to read env variables in a production environment.
So...
$ heroku config:set NODE_ENV=production
$ heroku config:set NODE_PATH=lib
There is no need to modify any file for a heroku deployment.
You are missing "models" in the "dependencies" property of your package.json. (I checked the github repo).
EDIT: sorry, looks like you are trying to use the module under /lib/models/ folder. So in this line https://github.com/gravityonmars/nodejs-starter/blob/master/index.js#L20 you can do this instead:
require('./lib/models')(app);
You just need to re-install models.
Do npm install models --save
then re-deploy your app to Heroku.
This should solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.