[英]Heroku Deploy Error: Cannot get Node App running after Deploy : Cannot find module '/app/web.js'
我有一個使用Express和MongoDB(貓鼬)的node.js應用程序。 它在本地運行良好。 我將它部署到heroku似乎沒有問題,但是當我嘗試實際啟動該應用程序時,它崩潰了。 heroku日志說:錯誤:找不到模塊'/app/web.js'
我對此並不陌生,因此不勝感激。 謝謝! 應用程序將幫助我的1型糖尿病女兒。
的package.json:
{
"name": "projectglu",
"version": "0.0.0",
"dependencies": {
"express": "~3.4.3",
"lodash": "~2.4.1",
"mongoose": "~3.8.8",
"connect-mongo": "~0.4.0",
"passport": "~0.2.0",
"passport-local": "~0.1.6",
"ejs": "~0.8.4"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-autoprefixer": "~0.4.0",
"grunt-bower-install": "~0.7.0",
"grunt-concurrent": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-compass": "~0.6.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-imagemin": "~0.5.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.5.2",
"grunt-google-cdn": "~0.2.0",
"grunt-newer": "~0.5.4",
"grunt-ngmin": "~0.0.2",
"grunt-rev": "~0.1.0",
"grunt-svgmin": "~0.2.0",
"grunt-usemin": "~2.0.0",
"jshint-stylish": "~0.1.3",
"load-grunt-tasks": "~0.2.0",
"time-grunt": "~0.2.1",
"grunt-express-server": "~0.4.5",
"grunt-open": "~0.2.0",
"connect-livereload": "~0.3.0",
"karma-ng-scenario": "~0.1.0",
"grunt-karma": "~0.6.2",
"karma-firefox-launcher": "~0.1.3",
"karma-script-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.5",
"karma-chrome-launcher": "~0.1.2",
"requirejs": "~2.1.10",
"karma-requirejs": "~0.2.1",
"karma-coffee-preprocessor": "~0.1.2",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.10.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
"grunt-mocha-test": "~0.8.1",
"supertest": "~0.8.2",
"should": "~2.1.0",
"grunt-env": "~0.4.1",
"grunt-node-inspector": "~0.1.3",
"grunt-nodemon": "~0.2.0",
"open": "~0.0.4"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test"
}
}
更清楚地講,問題可能出在從Heroku網站示例創建Procfile時,您正在剪切並粘貼“ web:node web.js”,這基本上告訴heroku哪個文件是您的入口點。 您可能有另一個入口點,例如說.. server.js,因此將“ web:node web.js”換為“ web:node server.js”即可解決您的問題。
造成此問題的原因有很多。
請檢查是否已添加“ Procfile”。使用Procfile(應用程序根目錄中的文本文件)明確聲明應執行的命令以啟動Web dyno。 在這種情況下,您只需要使用node執行Node腳本。
這是一個Procfile示例:
web: node web.js
另一個原因可能是配置錯誤的環境變量NODE_ENV
。 就個人而言,命令Heroku設置NODE_ENV=production
幫助我解決了我遇到的“ Cannot find module
錯誤。 執行此操作時, 請用 Heroku應用名稱替換myapp
。
heroku labs:enable user-env-compile -a myapp heroku config:set NODE_ENV=production
如果這不能解決您的問題, devDependencies
聲明的軟件包移到dependencies
只是為了減輕NODE_ENV
問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.