将angular 9应用程序部署到heroku-部署成功但不起作用

时间:2020-04-17 11:26:57

标签: angular heroku

答案

我在package.json中没有

"express":"^4.17.1",

"body-parser":"^1.19.0"

在依赖项中

///////////////////////////////////////////

我试图将我的angular 9应用程序部署到heroku

  1. 我将server.js文件添加到了根目录
  2. 我将“开始”更改为“ node server.js”

该应用程序已成功编译,但得到提示: “应用程序错误 应用程序中发生错误,无法提供您的页面。如果您是应用程序所有者,请检查日志以获取详细信息。您可以使用命令“

从Heroku CLI执行此操作

package.json:

{
  "name": "student-to-mentor-client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "heroku-postbuild": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.1",
    "@angular/cli": "~9.0.2",
    "@angular/compiler-cli": "~9.0.1",
    "@angular/cdk": "^9.2.0",
    "@angular/common": "~9.0.1",
    "@angular/compiler": "~9.0.1",
    "@angular/core": "~9.0.1",
    "@angular/forms": "~9.0.1",
    "@angular/http": "^7.2.16",
    "@angular/material": "^9.2.0",
    "@angular/platform-browser": "~9.0.1",
    "@angular/platform-browser-dynamic": "~9.0.1",
    "@angular/router": "~9.0.1",
    "@material/dialog": "^5.1.0",
    "bootstrap": "^3.4.1",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.2",
    "@angular/cli": "~9.0.2",
    "@angular/compiler-cli": "~9.0.1",
    "@angular/language-service": "~9.0.1",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~5.18.0",
    "typescript": "~3.7.5"
  },
  "engines": {
    "node": "10.15.3",
    "npm": "6.4.1"
  }
}

server.js

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

const app = express();

app.use(express.static('./dist/MentorToStudent_Client'));

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

res.sendFile(path.join(__dirname,'./dist/MentorToStudent_Client/index.html'));
});

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

heroku日志

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  10.15.3
       engines.npm (package.json):   6.4.1

       Resolving node version 10.15.3...
       Downloading and installing node 10.15.3...
       npm 6.4.1 already installed with node

-----> Restoring cache
       - node_modules

-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       audited 15663 packages in 13.701s
       found 2 low severity vulnerabilities
         run `npm audit fix` to fix them, or `npm audit` for details

-----> Build
       Running build

       > student-to-mentor-client@0.0.0 build /tmp/build_36d2d6939d3ac760e14a5ab5486fc99d
       > ng build

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

       chunk {runtime} runtime-es2015.js, runtime-es2015.js.map (runtime) 6.16 kB [entry] [rendered]
       chunk {runtime} runtime-es5.js, runtime-es5.js.map (runtime) 6.16 kB [entry] [rendered]
       chunk {styles} styles-es2015.js, styles-es2015.js.map (styles) 9.73 kB [initial] [rendered]
       chunk {styles} styles-es5.js, styles-es5.js.map (styles) 11 kB [initial] [rendered]
       chunk {main} main-es2015.js, main-es2015.js.map (main) 240 kB [initial] [rendered]
       chunk {main} main-es5.js, main-es5.js.map (main) 265 kB [initial] [rendered]
       chunk {polyfills} polyfills-es2015.js, polyfills-es2015.js.map (polyfills) 141 kB [initial] [rendered]
       chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 656 kB [initial] [rendered]
       chunk {vendor} vendor-es2015.js, vendor-es2015.js.map (vendor) 3.72 MB [initial] [rendered]
       chunk {vendor} vendor-es5.js, vendor-es5.js.map (vendor) 4.39 MB [initial] [rendered]
       Date: 2020-04-17T12:01:03.501Z - Hash: a3c1c0e77ff01fc0442e - Time: 48701ms
WARNING in ./src/app/register/register.component.css
Module Warning (from ./node_modules/postcss-loader/src/index.js):
Warning
(69:4) Gradient has outdated direction syntax. New syntax is like `to left` instead of `right`.

-----> Caching build
       - node_modules

-----> Pruning devDependencies
       removed 975 packages and audited 3092 packages in 14.344s
       found 0 vulnerabilities


-----> Build succeeded!
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 72.2M
-----> Launching...
       Released v6

我希望有人可以提供帮助或得到建议,这可能是什么问题??

即使本地主机8080也可以正常运行(节点server.js-命令)

1 个答案:

答案 0 :(得分:0)

尝试运行heroku logs来查看它引发了什么样的错误。