Angular 8 Web应用程序无法部署到Heroku

时间:2019-11-23 16:10:36

标签: node.js angular heroku

我觉得我的Angular应用程序已完全设置为可部署到Heroku,但由于某种原因,它仅在构建过程中挂起,并且从未继续运行-最终导致生成失败消息,但没有日志。

这是heroku日志的一部分--tail:

   -----> Build
   Detected both "build" and "heroku-postbuild" scripts
   Running heroku-postbuild

   > flux-admin@1.0.0 heroku-postbuild /tmp/build_d18bae1ef2310aacfb6851eddfeab6d1
   > ng build --prod

   Generating ES5 bundles for differential loading...
   ES5 bundle generation complete.

   chunk {0} runtime-es2015.edb2fcf2778e7bf1d426.js (runtime) 1.45 kB [entry] [rendered]
   chunk {0} runtime-es5.edb2fcf2778e7bf1d426.js (runtime) 1.45 kB [entry] [rendered]
   chunk {1} main-es2015.b5ce220634282bd1233e.js (main) 1010 kB [initial] [rendered]
   chunk {1} main-es5.b5ce220634282bd1233e.js (main) 1.08 MB [initial] [rendered]
   chunk {2} polyfills-es2015.2987770fde9daa1d8a2e.js (polyfills) 36.4 kB [initial] [rendered]
   chunk {3} polyfills-es5.df1101cc1e7b588877f8.js (polyfills-es5) 122 kB [initial] [rendered]
   chunk {4} styles.c1cdb3f05888558b2d70.css (styles) 60.6 kB [initial] [rendered]
   Date: 2019-11-23T15:43:44.636Z - Hash: 80ca71603894ea5db348 - Time: 114953ms

那是它的悬挂点。

这是我的package.json文件:

"name": "flux-admin",
"version": "1.0.0",
"scripts": {
  "ng": "ng",
  "start": "node server.js",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e",
  "heroku-prebuild": "",
  "heroku-postbuild": "ng build --prod"
},
"private": true,
"dependencies": {
  "@angular/animations": "~8.2.14",
  "@angular/cdk": "~7.3.3",
  "@angular/cli": "~8.3.19",
  "@angular/common": "~8.2.14",
  "@angular/compiler": "~8.2.14",
  "@angular/compiler-cli": "^8.2.14",
  "@angular-devkit/build-angular": "~0.803.19",
  "@angular/core": "~8.2.14",
  "@angular/forms": "~8.2.14",
  "@angular/material": "^7.3.3",
  "@angular/platform-browser": "~8.2.14",
  "@angular/platform-browser-dynamic": "~8.2.14",
  "@angular/router": "~8.2.14",
  "core-js": "^2.5.4",
  "path": "^0.12.7",
  "rxjs": "~6.5.3",
  "express": "^4.17.1",
  "rxjs-compat": "^6.4.0",
  "tslib": "^1.9.0",
  "typescript": "~3.5.3",
  "zone.js": "~0.9.1"
},
"devDependencies": {
  "@angular/cli": "~8.3.19",
  "@angular/compiler-cli": "^8.2.14",
  "@angular/language-service": "~8.2.14",
  "@types/jasmine": "~2.8.8",
  "@types/jasminewd2": "~2.0.3",
  "@types/node": "~8.9.4",
  "codelyzer": "^5.0.1",
  "enhanced-resolve": "^3.3.0",
  "jasmine-core": "~2.99.1",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~4.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": "~3.5.3"
},
"engines": {
  "node": "11.10.0",
  "npm": "6.13.1"
}

我的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/flux-admin'));

app.get('/*', function(req,res) {

res.sendFile(path.join(__dirname+'/dist/flux-admin/index.html'));
});

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

以防万一我还添加了一个Procfile:

web: node server.js

当我尝试在本地运行ng build --prod --aot时-它确实成功完成,因此似乎没有继续进行heroku部署过程的下一步(我相信它将是start脚本)

我的设置有明显的错误吗?

更新

在尝试进行多次部署之后,我最终降级回了Angular 7,并且毫无问题地部署了它!

我认为问题必须与在Angular 8中运行ng build --prod --aot的新方式有关,但是我完全不确定原因或原因。因此,现在,我将继续使用Angular 7并发布错误报告。

0 个答案:

没有答案