我已经尝试将Angular 7应用程序部署到Heroku几天了,并且在构建成功后一直遇到应用程序错误。我意识到我的整个/ dist文件夹都位于.gitignore中,因此我将其删除了,但仍然遇到应用程序错误。我检查了heroku日志(“启动脚本失败”),这是我跳出来的错误,不确定如何继续:
TypeError:对象原型只能是一个Object或为null: dist / hockey-app在Function.create()在 Function.serveStatic [静态] (/app/node_modules/serve->static/index.js:48:21)。 (/app/server.js:7:23)
这是node_modules / serve-> static / index.js的样子:在指示的行:
// copy options object
var opts = Object.create(options || null)
编辑:Server.js
const express = require('express');
const http = require('http')
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'dist/hockey-app')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/dist/hockey-app/index.html'));
});
const port = process.env.PORT || 3000;
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log('running'));
和我的package.json
{
"name": "hockey-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "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"
}
}
任何帮助将不胜感激
答案 0 :(得分:0)
现在查看您的server.js文件... express.static()
方法不应该接受您传递的内容。
尝试使用path.join(__dirname, "path/to/index")
,然后将完整路径传递给静态方法。