Angular 7应用程序部署到Heroku-构建失败,应用程序错误
我正在尝试将Angular应用程序部署到Heroku。我做这件事的经验有限,而且遇到了错误。我对stackoverflow的搜索导致我尝试了不同的配置,但每次都出现错误。我得到的最接近的结果是,我没有在脚本中包含postinstall,在这种情况下,构建成功了,但我仍然收到了相同的代码H10应用程序错误 我尝试了两种postinstall:ng build-aot-prod、“heroku postbuild”:“ng build-aot-prod”和“ng build-aot-prod”,但没有区别,由于这一行,每次构建都会失败 这是我的package.jsonAngular 7应用程序部署到Heroku-构建失败,应用程序错误,angular,heroku,Angular,Heroku,我正在尝试将Angular应用程序部署到Heroku。我做这件事的经验有限,而且遇到了错误。我对stackoverflow的搜索导致我尝试了不同的配置,但每次都出现错误。我得到的最接近的结果是,我没有在脚本中包含postinstall,在这种情况下,构建成功了,但我仍然收到了相同的代码H10应用程序错误 我尝试了两种postinstall:ng build-aot-prod、“heroku postbuild”:“ng build-aot-prod”和“ng build-aot-prod”,但没
{
"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"
}
}
myserver.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=错误代码=H10
desc=应用程序崩溃方法=获取路径=/
主机=nhl-hockey-app.herokuapp.com
请求id=cd86c7cd-aaa3-489f-b4ce-bb1c0a1f7e90 fwd=151.202.21.77
dyno=连接=服务=状态=503字节=协议=https
2019-02-19T23:35:02.861982+00:00 heroku[路由器]:at=错误代码=H10
desc=应用程序崩溃方法=获取路径=/favicon.ico
主机=nhl-hockey-app.herokuapp.com
请求id=1f51f401-9349-4ae6-9d1e-a354fffff8ee fwd=151.202.21.77
dyno=连接=服务=状态=503字节=协议=https
使用heroku postbuild,它将替换正常的构建脚本。如果使用postinstall,它将构建应用程序两次npm运行postinstall&&npm运行构建。当您将代码推送到heroku时,应该能够看到它 当您的应用程序成功构建时,heroku将使用启动脚本启动您的应用程序。我认为您的启动脚本在heroku上不起作用,因为并发是一个npm模块,我在package.json和ng build-watch中没有看到它,它是用于本地开发的,而不是用于在heroku上运行代码 我建议您在项目文件夹中创建一个Procfile。 Heroku将使用此命令启动您的应用程序,即服务器。 程序文件:
web: node server.js
试着移动
"@angular/cli": "~6.2.5",
"@angular/compiler-cli": "^6.1.0"
从devDependencies到dependencies…您有一个错误:“thisPlayer”是私有的,只能在类“PlayerDetailComponent”中访问。src/app/player detail/player detail.component.html24,39::属性“thisPlayer”是私有的,只能在类“PlayerDetailComponent”中访问。src/app/player detail/player detail.component.html29,20::属性“thisPlayer”是私有的,只能在类“PlayerDetailComponent”中访问。只需在组件PlayerDetailComponent中将属性thisPlayer定义为public。是的,我对此表示怀疑。修复了它,现在构建完成了,但是我仍然有相同的应用程序错误:上面包括尝试将server.js定义为:从这个问题开始:谢谢,我更新了server.js文件,但是我继续得到相同的应用程序错误。注意,我将heroku应用程序连接到github,以查看主程序的更新,并在每次推送新主程序时生成。此外,在更新github remote之前,我手动构建了应用程序ng build,以便在我的应用程序目录中创建dist文件夹,不确定这是否会导致任何问题在本地环境中使用npm时,npm是否开始工作?在ng build之后,您的dist是否包括hokey应用程序子目录?