简体   繁体   English

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

[英]Application error in Angular 6 app deployed to heroku

I am trying to deploy an angular 6 app to heroku first time. 我正在尝试首次将angular 6应用程序部署到heroku。 I don't have idea what is going wrong. 我不知道出了什么问题。

I have created an angular app which is working fine on localhost but when i deploy to heroku it gives "Application Error" 我创建了一个可在localhost上正常运行的有角度的应用程序,但是当我部署到heroku时会显示“ Application Error”

Application url: https://todo-app-joharzmn.herokuapp.com/ 应用网址: https//todo-app-joharzmn.herokuapp.com/

Here is my server.js file: 这是我的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);

my package.json file: 我的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" 
  }
}

application logs: 应用程序日志:

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

Note: App was built successfully. 注意:应用程序已成功构建。 There was not error. 没有错误。

Update: Solved by adding express in package.json file under dependencies. 更新:通过在依赖项下的package.json文件中添加express解决。 "express": "^4.16.3" “表达”:“ ^ 4.16.3”

The problem was with express. 问题是快递。

Solved by adding express in package.json file under dependencies. 通过在依赖项下的package.json文件中添加express来解决。

"express": "^4.16.3"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM