尝试将Angular 6应用程序部署到Heroku时出现H10错误

时间:2018-10-10 17:07:04

标签: node.js angular heroku

我已经遵循了一些有关如何将Angular SPA部署到Heroku的教程,但是我一直遇到相同的H10错误。我知道这意味着我的应用程序崩溃了,但是它运行良好,并且可以在本地完美运行。

我找到的所有解决方案都围绕端口号以及用于预安装和后构建的不同脚本。其中大多数解决了R10错误问题,这些问题与H10一起出现-但我只看到H10。

我已经完成的事情:

  • 将devdepency移至package.json中的依赖项
  • 将引擎添加到我的package.json中
  • 已安装增强型解析3.3.0
  • 已安装的快递服务器

这是我得到的实际日志:

    2018-10-10T16:19:29.000000+00:00 app[api]: Build succeeded
2018-10-10T16:19:43.620159+00:00 heroku[web.1]: Starting process with command `npm start`
2018-10-10T16:19:47.153473+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-10T16:19:47.136385+00:00 heroku[web.1]: Process exited with status 1
2018-10-10T16:19:47.026013+00:00 app[web.1]:
2018-10-10T16:19:47.026044+00:00 app[web.1]: > my-app@0.0.0 start /app
2018-10-10T16:19:47.026046+00:00 app[web.1]: > ng serve
2018-10-10T16:19:47.026047+00:00 app[web.1]:
2018-10-10T16:19:47.039479+00:00 app[web.1]: sh: 1: ng: not found
2018-10-10T16:19:47.043090+00:00 app[web.1]: npm ERR! file sh
2018-10-10T16:19:47.043753+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-10T16:19:47.044259+00:00 app[web.1]: npm ERR! errno ENOENT
2018-10-10T16:19:47.044547+00:00 app[web.1]: npm ERR! syscall spawn
2018-10-10T16:19:47.046756+00:00 app[web.1]: npm ERR! my-app@0.0.0 start: `ng serve`
2018-10-10T16:19:47.046979+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-10-10T16:19:47.047371+00:00 app[web.1]: npm ERR!
2018-10-10T16:19:47.047681+00:00 app[web.1]: npm ERR! Failed at the my-app@0.0.0 start script.
2018-10-10T16:19:47.047990+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-10T16:19:47.061989+00:00 app[web.1]:
2018-10-10T16:19:47.062221+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-10T16:19:47.062467+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-10-10T16_19_47_051Z-debug.log
2018-10-10T16:20:39.392693+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myapp.herokuapp.com request_id=1bead4ae-0135-4c00-9df7-e7638a1f5545 fwd="99.95.64.209" dyno= connect= service= status=503 bytes= protocol=https
2018-10-10T16:20:40.506320+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myapp.herokuapp.com request_id=0ec9a51e-e0b3-4bb7-8544-f34468d00640 fwd="99.95.64.209" dyno= connect= service= status=503 bytes= protocol=https

这是我的package.json:

{
  "name": "my-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 http-server",
    "heroku-postbuild": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/cli": "^6.2.4",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/compiler-cli": "^6.1.9",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "@toverux/ngx-sweetalert2": "^4.0.0",
    "angular-2-local-storage": "^2.0.0",
    "balloon-css": "^0.5.0",
    "core-js": "^2.5.4",
    "express": "^4.16.3",
    "path": "^0.12.7",
    "rxjs": "^6.0.0",
    "sweetalert2": "^7.25.6",
    "typescript": "~2.7.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "^6.2.4",
    "@angular/compiler-cli": "^6.1.9",
    "@angular/language-service": "^6.0.3",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "angular-cli-ghpages": "^0.5.3",
    "codelyzer": "~4.2.1",
    "enhanced-resolve": "^3.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  },
  "engines": {
    "node": "8.9.4",
    "npm": "5.6.0"
  }
}

以及我创建的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(__dirname + '/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);

0 个答案:

没有答案
相关问题