部署到heroku的Angular 6应用中的应用错误

时间:2018-09-22 11:16:22

标签: node.js angular express heroku deployment

我正在尝试第一次将angular 6应用程序部署到heroku。我不知道出了什么问题。

我创建了一个可在localhost上正常运行的有角度的应用程序,但是当我部署到heroku时,它会显示“应用程序错误”

应用程序网址:https://todo-app-joharzmn.herokuapp.com/

这是我的server.js文件:

//Install express server
const express = require('express');
const path = require('path');

const app = express();

// Serve only the static files form the dist directory
app.use(express.static('./dist'));

app.get('/*', function(req,res) {
  res.sendFile(path.join(__dirname,'/dist/index.html'));
});

// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);

我的package.json文件:

    {
  "name": "todo-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e", 
    "preinstall": "npm install -g @angular/cli @angular/compiler-cli typescript",
    "postinstall": "ng build --aot --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^6.2.3",
    "@angular/compiler-cli": "^6.1.8",
    "@angular/animations": "^6.1.8",
    "@angular/cdk": "^6.4.7",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/material": "^6.4.7",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.2.0",
    "zone.js": "~0.8.26", "typescript": "~2.9.2"

  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "^6.2.3",
    "@angular/compiler-cli": "^6.1.8",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  },
  "engines": { 
    "node": "8.12.0", 
    "npm": "6.4.1" 
  }
}

应用程序日志:

2018-09-22T11:00:07.817882+00:00 app[web.1]: npm ERR! todo-app@0.0.0 start: `node server.js`
2018-09-22T11:00:07.818117+00:00 app[web.1]: npm ERR! Exit status 1
2018-09-22T11:00:07.819425+00:00 app[web.1]: npm ERR! 
2018-09-22T11:00:07.819681+00:00 app[web.1]: npm ERR! Failed at the todo-app@0.0.0 start script.
2018-09-22T11:00:07.819946+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-09-22T11:00:07.950231+00:00 app[web.1]: 
2018-09-22T11:00:07.961935+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-09-22T11:00:07.961944+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-09-22T11_00_07_822Z-debug.log
2018-09-22T11:00:09.438019+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=todo-app-joharzmn.herokuapp.com request_id=b0b530b0-c277-47d5-8e68-cd0a7b68df38 fwd="39.46.157.45" dyno= connect= service= status=503 bytes= protocol=https
2018-09-22T11:00:11.253970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=todo-app-joharzmn.herokuapp.com request_id=c597732a-5be7-41f0-bf5b-24f5012de2a1 fwd="39.46.157.45" dyno= connect= service= status=503 bytes= protocol=https

注意:应用程序已成功构建。没有错误。

更新: 通过在依赖项下的package.json文件中添加express来解决。     “表达”:“ ^ 4.16.3”

1 个答案:

答案 0 :(得分:0)

问题出在快递上。

通过在依赖项下的package.json文件中添加express来解决。

"express": "^4.16.3"