Angular 7 应用程序部署到 Heroku - 构建失败,应用程序错误

标签 angular heroku

我正在尝试将我的 Angular 应用程序部署到 Heroku。我在这方面的经验有限并且遇到了错误。我对 stackoverflow 的搜索让我尝试了不同的配置,但每次都会出错。我得到的最接近的是当我没有在脚本中包含“postinstall”时,在这种情况下构建成功,但我仍然收到相同的代码 H10 应用程序错误。

我尝试过“postinstall:ng build --aot --prod”、“heroku-postbuild”:“ng build --aot --prod”和 ng build --aot --prod”,但没有区别在于,由于这一行,每次构建都会失败。

这是我的 package.json

{
  "name": "hockey-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "concurrently \"ng build --watch\" \"node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "ng build --aot --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.10",
    "@angular/cdk": "^7.3.0",
    "@angular/cli": "~6.2.5",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/material": "^7.3.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "bootstrap": "^4.2.1",
    "core-js": "^2.5.4",
    "enhanced-resolve": "^4.1.0",
    "express": "^4.16.4",
    "path": "^0.12.7",
    "rxjs": "~6.2.0",
    "typescript": "~2.9.2",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "~6.2.5",
    "@angular/compiler-cli": "^6.1.0",
    "@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.11.4",
    "npm": "6.4.1"
  }
}

我的server.js

const express = require('express');
const path = require('path');

const app = express();

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

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

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

感谢任何帮助。谢谢。

编辑:构建成功并部署,但继续出现应用程序错误。 Heroku 日志:

2019-02-19T23:35:02.490703+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nhl-hockey-app.herokuapp.com request_id=cd86c7cd-aaa3-489f-b4ce-bb1c0a1f7e90 fwd="151.202.21.77" dyno= connect= service= status=503 bytes= protocol=https 2019-02-19T23:35:02.861982+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nhl-hockey-app.herokuapp.com request_id=1f51f401-9349-4ae6-9d1e-a354fffff8ee fwd="151.202.21.77" dyno= connect= service= status=503 bytes= protocol=https

最佳答案

尝试移动

"@angular/cli": "~6.2.5",
"@angular/compiler-cli": "^6.1.0"

devDependencies依赖项...

关于Angular 7 应用程序部署到 Heroku - 构建失败,应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54776088/

相关文章:

angular - 'mat-form-field' 不是已知元素 - Angular 4 和 Angular Material 2

java - 在Heroku中拾取JAVA_TOOL_OPTIONS包含RMI参数

jquery - Rails jquery 适用于本地主机,但不适用于 heroku

docker - Heroku 环境变量 $DATABASE_URL 和 $PORT 未在 dyno 中显示(heroku ps :exec)

django - 将 JSON 文件内容加载到 Heroku 环境变量

html - 如何在 mat-card-header 的左侧和右侧设置元素组?

html - 将内容左对齐的 div 居中

javascript - 仅在 Chrome 上的 Angular 项目中控制台上的 zone.js 违规警告

html - 根据内容使页脚底部一致

node.js - 为什么 Heroku 每天都会重置我的文件 "data.json"?