我的应用程序在本地运行,但是当部署到heroku时,找不到我的一个模块。我使用一个.gitignore文件来忽略node_modules文件夹,并允许heroku安装正确的依赖项。当我运行heroku open命令并使用heroku logs --tail搜索日志时,它将显示此错误。
我得到的错误是:
2015-10-21T14:42:58.415140+00:00 app[web.1]: Error: Cannot find module 'mongodb'
2015-10-21T14:42:58.415141+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:336:15)
2015-10-21T14:42:58.415142+00:00 app[web.1]: at Function.Module._load (module.js:278:25)
2015-10-21T14:42:58.415142+00:00 app[web.1]: at Module.require (module.js:365:17)
2015-10-21T14:42:58.415143+00:00 app[web.1]: at require (module.js:384:17)
2015-10-21T14:42:58.415144+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoskin/lib/index.js:14:13)
2015-10-21T14:42:58.415145+00:00 app[web.1]: at Module._compile (module.js:460:26)
2015-10-21T14:42:58.415145+00:00 app[web.1]: at Object.Module._extensions..js (module.js:478:10)
2015-10-21T14:42:58.415146+00:00 app[web.1]: at Module.load (module.js:355:32)
2015-10-21T14:42:58.415146+00:00 app[web.1]: at Function.Module._load (module.js:310:12)
2015-10-21T14:42:58.415147+00:00 app[web.1]: at Module.require (module.js:365:17)
2015-10-21T14:42:59.337084+00:00 heroku[web.1]: Process exited with status 1
2015-10-21T14:42:59.348953+00:00 heroku[web.1]: State changed from starting to crashed在本地,我的应用程序结构如下:
app/
config/
node_modules/
..
-mongodb
-mongoskin
..
public/当我使用bash搜索heroku目录时,我看不到mongodb模块。有什么问题吗?
发布于 2015-10-21 15:19:00
我已经想出答案了。我在本地删除了node_modules文件,并再次运行npm install,节点显示了以下警告:
npm WARN peerDependencies The peer dependency mongodb@~2.0 included from mongoskin will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.我必须在我的package.json文件中显式地声明mongoskin对mongodb的依赖关系,如下所示:
"dependencies": {
...
"mongoskin": "2.0.3",
"mongodb": "^2.0.46",
...
}我把它推给了heroku,它成功了。
https://stackoverflow.com/questions/33263047
复制相似问题