部署到 Heroku 错误:找不到模块“/app/server.js" [英] Deployment to Heroku Error: Cannot find module '/app/server.js'

查看:37
本文介绍了部署到 Heroku 错误:找不到模块“/app/server.js"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm deploying an Angular 6 application created with the angular-cli to Heroku. The build completes successfully, however, when I go to the deployed application, I get a blank page.

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

After running the Heroku logs, it appears the error/crash happens upon starting up the node server instance. "Cannot find module '/app/server/js". The server.js file lives under the src directory so I don't know why this is happening.

来自日志:

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

Here is the package.json, I removed the node and npm engines to run the default versions from the heroku build:

{
  "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:

And the 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);

文件树:

知道可能是什么问题吗?

Any idea on what the problem could be?

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

I added a Procfile at src/Procfile:

web: node src/server.js

添加此文件后,应用程序仍然崩溃,Heroku 日志中的输出如下:

After adding this file, the app still crashes with the following output in the Heroku logs:

推荐答案

创建包含以下内容的 Procfile

Create a Procfile with following content

web: node src/server.js

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

The Procfile is always a simple text file that is named Procfile exactly. For example, Procfile.txt is not valid.

Procfile 必须位于您应用的根目录中.如果放在其他地方,它就不起作用.

The Procfile must live in your app’s root directory. It does not function if placed anywhere else.

Heroku app dynos 执行 Procfile 的命令

Heroku app dynos executes the commands of Procfile

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

Read more about Procfile here https://devcenter.heroku.com/articles/procfile

这篇关于部署到 Heroku 错误:找不到模块“/app/server.js"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆