部署到Heroku错误:找不到模块' /app/server.js'

时间:2018-05-28 17:24:15

标签: node.js angular express heroku deployment

我将使用angular-cli创建的Angular 6应用程序部署到Heroku。构建成功完成,但是,当我转到已部署的应用程序时,我得到一个空白页。

运行Heroku日志后,启动节点服务器实例时会出现错误/崩溃。 "找不到模块' / app / server / js"。 server.js文件位于src目录下,所以我不知道为什么会这样。

来自日志: enter image description here

这是package.json,我删除了节点和npm引擎来运行heroku构建的默认版本:

{
  "name": "blog-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/cdk": "^6.0.0",
    "@angular/cli": "~6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/compiler-cli": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/material": "^6.0.1",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "@ngrx/effects": "^5.2.0",
    "@ngrx/store": "^5.2.0",
    "angularfire2": "^5.0.0-rc.8.1-next",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.4",
    "express": "^4.16.3",
    "firebase": "^5.0.2",
    "ngx-quill": "^3.1.0",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.1.0",
    "typescript": "~2.7.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.0",
    "@angular/language-service": "^6.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

和server.js:

import express from "express";
const app = express();

app.use(static(__dirname + '/dist'));

app.all('*', (req, res) => {
  res.status(200).sendFile(__dirname + '/dist/index.html');
});

app.listen(process.env.PORT || 8080);

文件树:

enter image description here

对问题可能是什么有任何想法?

编辑:我在src / Procfile中添加了一个Procfile:

web: node src/server.js

添加此文件后,应用程序仍会在Heroku日志中使用以下输出崩溃:

enter image description here

2 个答案:

答案 0 :(得分:5)

创建包含以下内容的Procfile

-30

Procfile始终是一个简单的文本文件,名为Procfile。例如,Procfile.txt无效。

Procfile必须存在于应用程序的根目录中。如果放在其他地方,它就不起作用。

Heroku app dynos执行Procfile命令

在此处阅读有关Procfile的更多信息https://devcenter.heroku.com/articles/procfile

答案 1 :(得分:4)

在主文件夹中创建Procfile并添加:

>>> keys = "VStr vNum EegMeg nChan trigPoint dType tmpSize[0] tmpSize[1] avgMat".split()
>>> dict(zip(keys,struct.unpack_from(">7sh7f",open("test.bin","rb").read())))
{'nChan': 0.0, 'EegMeg': 1.0, 'dType': 0.0, 'trigPoint': 1.0, 'VStr': 'Version', 'avgMat': -12.964995384216309, 'vNum': 8, 'tmpSize[0]': 65.0, 'tmpSize[1]': 1076.0}

检查下面的图片,将Procfile放在哪里:

visit link to view where to put Procfile