【发布时间】:2019-07-13 12:54:17
【问题描述】:
我正在尝试将我的 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[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET 路径="/" 主机=nhl-hockey-app.herokuapp.com request_id=cd86c7cd-aaa3-489f-b4ce-bb1c0a1f7e90 fwd="151.202.21.77" dyno=连接=服务=状态=503字节=协议=https 2019-02-19T23:35:02.861982+00:00 heroku[路由器]: at=error code=H10 desc="应用程序崩溃" 方法=GET path="/favicon.ico" 主机=nhl-hockey-app.herokuapp.com request_id=1f51f401-9349-4ae6-9d1e-a354fffff8ee fwd="151.202.21.77" dyno=连接=服务=状态=503字节=协议=https
【问题讨论】:
-
您有这个错误:
'thisPlayer' is private and only accessible within class 'PlayerDetailComponent'. src/app/player-detail/player-detail.component.html(24,39): : Property 'thisPlayer' is private and only accessible within class 'PlayerDetailComponent'. src/app/player-detail/player-detail.component.html(29,20): : Property 'thisPlayer' is private and only accessible within class 'PlayerDetailComponent'.,只需在您的组件 PlayerDetailComponent (github.com/angular/angular/issues/11422) 中将属性 thisPlayer 定义为 public。 -
是的,我对此表示怀疑。修复它,现在构建完成,但我仍然有相同的应用程序错误:包括在上面
-
尝试将你的 server.js 定义为:hastebin.com/zavehahide.js 来自这个问题:stackoverflow.com/questions/48479575/…
-
谢谢,我更新了 server.js 文件,但是我仍然收到相同的应用程序错误。请注意,我将 heroku 应用程序连接到 github 以观察 master 的更新,并在每次推送新的 master 时构建。另外,我手动构建了应用程序(ng build),以便在更新 github 远程之前在我的应用程序目录中创建 dist 文件夹,不确定这是否会导致任何问题
-
当您在本地环境中使用时,您的 npm 是否开始工作?您的 dist 在 ng build 后是否包含 hokey-app 子目录?