如何摆脱错误:在Heroku上找不到模块'模型' [英] How can I get rid of Error: Cannot find module 'models' on Heroku

查看:88
本文介绍了如何摆脱错误:在Heroku上找不到模块'模型'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直收到这个错误:错误:找不到模块'模型'在Heroku上。我使用Node.JS.我正在使用这个Node.JS项目



我将Heroku中的日志和由于长度限制在一个要点



这里的摘录:

  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:Can not find module'models'

我在Heroku上设置了我的配置,并且有一个mongolab mongodb设置,配置val MONGO_URL被设置,并且NODE_ENV被设置为生产。



您可以找到该网站这里



有谁知道这是怎么回事?感谢您的帮助!

解决方案

您需要设置 NODE_PATH = lib to heroku的配置变量。

NODE_PATH 告诉节点除了 node_modules 目录。



此外,你需要告诉应用程序在生产环境中读取ENV变量。



因此...

  $ heroku上配置:设置NODE_ENV =生产
$ heroku上配置:集NODE_PATH = LIB

有不需要修改任何文件用于Heroku的部署。


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.

这篇关于如何摆脱错误:在Heroku上找不到模块'模型'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆