[英]How can I get rid of Error: Cannot find module 'models' on Heroku
I keep receiving this error: "Error: Cannot find module 'models'" on Heroku. 我一直收到这个错误:“错误:在Heroku上找不到模块'模型'”。 I'm using Node.JS. 我正在使用Node.JS. I'm using this Node.JS project . 我正在使用这个Node.JS项目 。
I copied out the logs from Heroku and put them in a gist due to length. 我从Heroku中复制了日志, 并将它们放在一个要点中 。
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. 我在Heroku上设置了我的配置,并设置了mongolab mongodb,并设置了配置MONGO_URL,并将NODE_ENV设置为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=lib
设置为heroku的配置变量。
NODE_PATH
tells node where to find modules besides node_modules
directory. NODE_PATH
告诉节点除了node_modules
目录之外node_modules
哪里找到模块。
Also, you need to tell the app to read env variables in a production environment. 此外,您需要告诉应用程序在生产环境中读取env变量。
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. 没有必要为heroku部署修改任何文件。
You are missing "models" in the "dependencies" property of your package.json. 您缺少package.json的“dependencies”属性中的“models”。 (I checked the github repo). (我检查了github回购)。
EDIT: sorry, looks like you are trying to use the module under /lib/models/ folder. 编辑:抱歉,看起来你正在尝试使用/ lib / models /文件夹下的模块。 So in this line https://github.com/gravityonmars/nodejs-starter/blob/master/index.js#L20 you can do this instead: 所以在这行https://github.com/gravityonmars/nodejs-starter/blob/master/index.js#L20中你可以这样做:
require('./lib/models')(app); 要求(” ./ LIB /模型)(应用程序);
You just need to re-install models. 您只需要重新安装模型。
Do npm install models --save
then re-deploy your app to Heroku. 做npm install models --save
然后将您的应用重新部署到Heroku。
This should solve your problem. 这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.