【发布时间】:2017-07-17 10:02:03
【问题描述】:
我正在尝试使用 Git 将 Angular 应用程序部署到 Heroku。使用 Angular CLI 并在 localhost 查看时,该应用程序功能齐全。我有一个用于提供静态文件的小型 Node.js 服务器。
我的 Heroku 部署被标记为已构建且没有错误,但在尝试连接时,它失败了。
Heroku 日志:
heroku[web.1]: Starting process with command `node ../server.js`
[web.1]: module.js:471
app[web.1]: throw err;
app[web.1]: ^
app[web.1]:
app[web.1]: Error: Cannot find module '/server.js'
app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
app[web.1]: at Function.Module._load (module.js:417:25)
app[web.1]: at Module.runMain (module.js:604:10)
app[web.1]: at run (bootstrap_node.js:389:7)
app[web.1]: at startup (bootstrap_node.js:149:9)
app[web.1]: at bootstrap_node.js:504:3
heroku[web.1]: State changed from starting to crashed
我看到它找不到server.js,但它肯定在我的根目录中并用 git 跟踪/推送:
>git ls-files
Procfile
dist/...
...
package.json
protractor.conf.js
server.js
src/app/app.component.css
src/app/app.component.html
src/app/app.component.ts
src/app/app.module.ts
src/app/tenant.ts
...
过程文件:
web: node ../server.js
server.js:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.listen(process.env.PORT || 8080);
package.json,我将private 设置为false:
{
"name": "utilites",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node ../server.js",
"build": "ng build",
...
},
"private": false,
"dependencies": {
"@angular/animations": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/cli": "1.1.2",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
...
},
...
}
/dist 是用ng build --aot -prod 生成的。
有什么想法吗?如果我忽略了提供调试此部署所需的任何内容,请告诉我。感谢您的宝贵时间。
解决方案
问题很简单:“../server.js”应该只是 package.json 和 procfile 中的 server.js。
【问题讨论】:
标签: node.js git angular heroku deployment