意味着全栈应用程序未部署在 Heroku 应用程序错误上
Posted
技术标签:
【中文标题】意味着全栈应用程序未部署在 Heroku 应用程序错误上【英文标题】:MEAN Full Stack app not deploying on Heroku Application Error 【发布时间】:2020-12-21 08:42:56 【问题描述】:我正在尝试在 heroku 上使用 mongodb 将我的平均堆栈应用程序部署到后端数据库,但它给出了应用程序错误。我已经粘贴了 heroku 的日志和我的 package.json 文件。
Heroku 日志:
2020-09-02T07:29:30.163006+00:00 app[web.1]: npm ERR! Failed at the mean-app@0.0.0 start script.
2020-09-02T07:29:30.163090+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There
is likely additional logging output above.
2020-09-02T07:29:30.172713+00:00 app[web.1]:
2020-09-02T07:29:30.172942+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-02T07:29:30.173226+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-09-02T07_29_30_164Z-
debug.log
2020-09-02T07:29:30.223791+00:00 heroku[web.1]: Process exited with status 1
2020-09-02T07:29:30.260565+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-02T07:35:27.123519+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-02T07:35:31.746958+00:00 heroku[web.1]: Starting process with command `npm start`
2020-09-02T07:35:34.033496+00:00 app[web.1]:
2020-09-02T07:35:34.033513+00:00 app[web.1]: > mean-app@0.0.0 start /app
2020-09-02T07:35:34.033514+00:00 app[web.1]: > node server.js
2020-09-02T07:35:34.033514+00:00 app[web.1]:
2020-09-02T07:35:34.211459+00:00 app[web.1]: internal/modules/cjs/loader.js:968
2020-09-02T07:35:34.211461+00:00 app[web.1]: throw err;
2020-09-02T07:35:34.211461+00:00 app[web.1]: ^
2020-09-02T07:35:34.211462+00:00 app[web.1]:
2020-09-02T07:35:34.211462+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2020-09-02T07:35:34.211462+00:00 app[web.1]: Require stack:
2020-09-02T07:35:34.211463+00:00 app[web.1]: - /app/backend/models/post.js
2020-09-02T07:35:34.211463+00:00 app[web.1]: - /app/backend/app.js
2020-09-02T07:35:34.211464+00:00 app[web.1]: - /app/server.js
2020-09-02T07:35:34.211464+00:00 app[web.1]: at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:965:15)
2020-09-02T07:35:34.211465+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:841:27)
2020-09-02T07:35:34.211465+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:1025:19)
2020-09-02T07:35:34.211465+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-09-02T07:35:34.211466+00:00 app[web.1]: at Object.<anonymous> (/app/backend/models/post.js:2:18)
2020-09-02T07:35:34.211466+00:00 app[web.1]: at Module._compile
(internal/modules/cjs/loader.js:1137:30)
2020-09-02T07:35:34.211467+00:00 app[web.1]: at Object.Module._extensions..js
(internal/modules/cjs/loader.js:1157:10)
2020-09-02T07:35:34.211467+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:985:32)
2020-09-02T07:35:34.211467+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:878:14)
2020-09-02T07:35:34.211468+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:1025:19)
2020-09-02T07:35:34.211468+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-09-02T07:35:34.211468+00:00 app[web.1]: requireStack: [
2020-09-02T07:35:34.211469+00:00 app[web.1]: '/app/backend/models/post.js',
2020-09-02T07:35:34.211469+00:00 app[web.1]: '/app/backend/app.js',
2020-09-02T07:35:34.211470+00:00 app[web.1]: '/app/server.js'
2020-09-02T07:35:34.211470+00:00 app[web.1]: ]
2020-09-02T07:35:34.211470+00:00 app[web.1]:
2020-09-02T07:35:34.220729+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-02T07:35:34.221090+00:00 app[web.1]: npm ERR! errno 1
2020-09-02T07:35:34.223600+00:00 app[web.1]: npm ERR! mean-app@0.0.0 start: `node server.js`
2020-09-02T07:35:34.223754+00:00 app[web.1]: npm ERR! Exit status 1
2020-09-02T07:35:34.223917+00:00 app[web.1]: npm ERR!
2020-09-02T07:35:34.224043+00:00 app[web.1]: npm ERR! Failed at the mean-app@0.0.0 start script.
2020-09-02T07:35:34.224189+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There
is likely additional logging output above.
2020-09-02T07:35:34.235076+00:00 app[web.1]:
2020-09-02T07:35:34.235345+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-02T07:35:34.235483+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-09-02T07_35_34_225Z-
debug.log
2020-09-02T07:35:34.294877+00:00 heroku[web.1]: Process exited with status 1
2020-09-02T07:35:34.336381+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-02T07:35:34.338258+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-02T07:35:41.000000+00:00 app[api]: Build succeeded
2020-09-02T07:35:42.772327+00:00 heroku[web.1]: Starting process with command `npm start`
2020-09-02T07:35:46.548576+00:00 app[web.1]:
2020-09-02T07:35:46.548586+00:00 app[web.1]: > mean-app@0.0.0 start /app
2020-09-02T07:35:46.548586+00:00 app[web.1]: > node server.js
2020-09-02T07:35:46.548586+00:00 app[web.1]:
2020-09-02T07:35:46.821836+00:00 app[web.1]: internal/modules/cjs/loader.js:968
2020-09-02T07:35:46.821878+00:00 app[web.1]: throw err;
2020-09-02T07:35:46.821879+00:00 app[web.1]: ^
2020-09-02T07:35:46.821879+00:00 app[web.1]:
2020-09-02T07:35:46.821879+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2020-09-02T07:35:46.821880+00:00 app[web.1]: Require stack:
2020-09-02T07:35:46.821885+00:00 app[web.1]: - /app/backend/models/post.js
2020-09-02T07:35:46.821885+00:00 app[web.1]: - /app/backend/app.js
2020-09-02T07:35:46.821886+00:00 app[web.1]: - /app/server.js
2020-09-02T07:35:46.821890+00:00 app[web.1]: at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:965:15)
2020-09-02T07:35:46.821890+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:841:27)
2020-09-02T07:35:46.821894+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:1025:19)
2020-09-02T07:35:46.821894+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-09-02T07:35:46.821894+00:00 app[web.1]: at Object.<anonymous> (/app/backend/models/post.js:2:18)
2020-09-02T07:35:46.821895+00:00 app[web.1]: at Module._compile
(internal/modules/cjs/loader.js:1137:30)
2020-09-02T07:35:46.821895+00:00 app[web.1]: at Object.Module._extensions..js
(internal/modules/cjs/loader.js:1157:10)
2020-09-02T07:35:46.821895+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:985:32)
2020-09-02T07:35:46.821896+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:878:14)
2020-09-02T07:35:46.821896+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:1025:19)
2020-09-02T07:35:46.821896+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-09-02T07:35:46.821896+00:00 app[web.1]: requireStack: [
2020-09-02T07:35:46.821897+00:00 app[web.1]: '/app/backend/models/post.js',
2020-09-02T07:35:46.821897+00:00 app[web.1]: '/app/backend/app.js',
2020-09-02T07:35:46.821897+00:00 app[web.1]: '/app/server.js'
2020-09-02T07:35:46.821898+00:00 app[web.1]: ]
2020-09-02T07:35:46.821898+00:00 app[web.1]:
2020-09-02T07:35:46.847916+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-02T07:35:46.848347+00:00 app[web.1]: npm ERR! errno 1
2020-09-02T07:35:46.852389+00:00 app[web.1]: npm ERR! mean-app@0.0.0 start: `node server.js`
2020-09-02T07:35:46.852586+00:00 app[web.1]: npm ERR! Exit status 1
2020-09-02T07:35:46.852827+00:00 app[web.1]: npm ERR!
2020-09-02T07:35:46.853679+00:00 app[web.1]: npm ERR! Failed at the mean-app@0.0.0 start script.
2020-09-02T07:35:46.853832+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There
is likely additional logging output above.
2020-09-02T07:35:46.861650+00:00 app[web.1]:
2020-09-02T07:35:46.861954+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-02T07:35:46.862058+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-09-02T07_35_46_855Z-
debug.log
2020-09-02T07:35:46.927186+00:00 heroku[web.1]: Process exited with status 1
2020-09-02T07:35:47.116783+00:00 heroku[web.1]: State changed from starting to crashed
这是 Angular 应用的 package.json 文件的脚本。
package.json
"name": "mean-app",
"version": "0.0.0",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"start:server": "nodemon server.js"
,
"private": true,
"dependencies":
"@angular/animations": "~10.0.2",
"@angular/cdk": "^10.1.0",
"@angular/common": "~10.0.2",
"@angular/compiler": "~10.0.2",
"@angular/core": "~10.0.2",
"@angular/forms": "~10.0.2",
"@angular/material": "^10.1.0",
"@angular/platform-browser": "~10.0.2",
"@angular/platform-browser-dynamic": "~10.0.2",
"@angular/router": "~10.0.2",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "^3.5.9",
"rxjs": "~6.5.5",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
,
"devDependencies":
"@angular-devkit/build-angular": "~0.1000.1",
"@angular/cli": "~10.0.1",
"@angular/compiler-cli": "~10.0.2",
"@types/angular": "^1.7.2",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0-next.1",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"mongoose": "^5.9.25",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.9.5"
请建议我任何解决方案,以便解决。
【问题讨论】:
可以分享一下文件夹结构吗 - .browserslistrc - .editorconfig - .gitignore - .vscode - angular.json - 后端 - e2e - karma.conf.js - node_modules - package-lock.json - package.json - README.md - server.js - src - tsconfig.app.json - tsconfig.base.json - tsconfig.json - tsconfig.spec.json - tslint.json 【参考方案1】:尝试重新安装猫鼬,不要使用 -g 标签。
npm install mongoose --save
基本上,错误是heroku服务器上没有安装mongoose。
【讨论】:
【参考方案2】:您已将猫鼬安装为devDependency
。当 Heroku 构建您的项目时,它会删除您所有的 devDependencies,因此在执行时,mongoose 是未定义的。
确保将猫鼬移至dependencies
。
我会运行npm uninstall mongoose
,然后运行npm i mongoose
以安装到您的dependencies
列表中
【讨论】:
以上是关于意味着全栈应用程序未部署在 Heroku 应用程序错误上的主要内容,如果未能解决你的问题,请参考以下文章
Heroku:Django Migration 版本未在部署中运行