[英]Heroku: Cannot find module 'mongodb'
OK, I have an express app which is throwing this error at launch when deployed to Heroku. 好的,我有一个Express应用程序,当部署到Heroku时会在启动时抛出此错误。 The app compiles and runs fine locally: 该应用程序可以在本地编译并正常运行:
Cannot find module 'mongodb'
This app was running until I redeployed it yesterday ... here is my package.json which was unchanged 这个应用程序一直运行到我昨天重新部署为止...这是我的package.json,它没有发生变化
{
"name": "fitness-tracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.9.0",
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"promise": "~6.0.1",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"debug": "~2.0.0",
"mongodb-core": "*",
"mongoskin": "~2.0.0",
"express-handlebars": "~1.1.0",
"moment": "~2.0.0",
"moment-timezone": "^0.3.1",
"q": "~1.0.1",
"compass": "~0.1.0",
"apm": "*"
},
"devDependencies": {
"moment-timezone": "^0.3.1"
}
Ideas? 有想法吗?
So the issue was package's resolution based on node version. 因此,问题在于基于节点版本的程序包解析。 Since NodeJS is rapidly evolving, it's a good practice to include engines
specification in your package.json
. 由于NodeJS迅速发展,因此在package.json
包含engines
规范是一个很好的实践。
When doing automatic deployments on various cloud providers, this helps them to use only specified node & npm version. 在各种云提供商上进行自动部署时,这可以帮助他们仅使用指定的节点和npm版本。 This was all the packages that get fetches are built for that node version hence less chances of app to misbehave. 这是所有获取的软件包都是针对该节点版本构建的,因此减少了应用程序异常的机会。
Read more: https://docs.npmjs.com/files/package.json#engines 了解更多: https : //docs.npmjs.com/files/package.json#engines
Also always worth a try: disable the Heroku build cache to recreate the node_modules
directory. 同样总是值得一试:禁用Heroku构建缓存以重新创建node_modules
目录。
In the Heroku CLI write: 在Heroku CLI中编写:
$ heroku config:set NODE_MODULES_CACHE=false
$ git commit -am 'disable node_modules cache' --allow-empty
$ git push heroku master
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.