[英]Heroku: Cannot find module 'mongodb'
好的,我有一個Express應用程序,當部署到Heroku時會在啟動時拋出此錯誤。 該應用程序可以在本地編譯並正常運行:
Cannot find module 'mongodb'
這個應用程序一直運行到我昨天重新部署為止...這是我的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"
}
有想法嗎?
因此,問題在於基於節點版本的程序包解析。 由於NodeJS迅速發展,因此在package.json
包含engines
規范是一個很好的實踐。
在各種雲提供商上進行自動部署時,這可以幫助他們僅使用指定的節點和npm版本。 這是所有獲取的軟件包都是針對該節點版本構建的,因此減少了應用程序異常的機會。
同樣總是值得一試:禁用Heroku構建緩存以重新創建node_modules
目錄。
在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.