【发布时间】:2020-04-17 21:46:21
【问题描述】:
回答:
我在 package.json 中没有
"express":"^4.17.1",
"body-parser":"^1.19.0"
在依赖项中
///////////////////////////////////
我尝试将我的 Angular 9 应用程序部署到 heroku
- 我将 server.js 文件添加到根目录
- 我将“start”更改为“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
我希望有人可以提供帮助或获得建议,这可能是什么问题???。
即使 localhost 8080 也可以工作(节点 server.js - 命令)
【问题讨论】:
-
添加此脚本
"postinstall": "ng build --aot -prod",然后重试。 -
我试过了 - 没用..