我的 node + express 应用程序在本地部署良好,但在推送到 heroku 时不会部署

凯尔·彭德加斯特

如果这是一个基本的解决方案,首先我很抱歉。我是 Node + Express 的新手,仍在努力解决一些概念!

我有一个在本地启动的 Node + Express 应用程序,但是当我推送到 heroku 或运行 heroku local web 时,它以代码 0 退出,并且不会产生任何错误代码供我诊断。

这是我部署到 Heroku 时日志的特定输出:

2018-06-30T11:58:37.052754+00:00 heroku[web.1]: Starting process with command `npm run build`
2018-06-30T11:58:39.336703+00:00 app[web.1]: 
2018-06-30T11:58:39.336728+00:00 app[web.1]: > [email protected] build /app
2018-06-30T11:58:39.336733+00:00 app[web.1]: > npm run clean && npm run build-babel
2018-06-30T11:58:39.336734+00:00 app[web.1]: 
2018-06-30T11:58:39.777160+00:00 app[web.1]: 
2018-06-30T11:58:39.777199+00:00 app[web.1]: > [email protected] clean /app
2018-06-30T11:58:39.777201+00:00 app[web.1]: > rm -rf build && mkdir build
2018-06-30T11:58:39.777202+00:00 app[web.1]: 
2018-06-30T11:58:40.305583+00:00 app[web.1]: 
2018-06-30T11:58:40.305603+00:00 app[web.1]: > [email protected] build-babel /app
2018-06-30T11:58:40.305605+00:00 app[web.1]: > babel -d ./build ./src -s
2018-06-30T11:58:40.305610+00:00 app[web.1]: 
2018-06-30T11:58:41.146122+00:00 app[web.1]: src/index.js -> build/index.js
2018-06-30T11:58:41.196474+00:00 app[web.1]: src/mailer.js -> build/mailer.js
2018-06-30T11:58:41.242714+00:00 app[web.1]: src/models/Circuit.js -> build/models/Circuit.js
2018-06-30T11:58:41.293304+00:00 app[web.1]: src/models/User.js -> build/models/User.js
2018-06-30T11:58:41.346985+00:00 app[web.1]: src/routes/auth.js -> build/routes/auth.js
2018-06-30T11:58:41.362022+00:00 app[web.1]: src/routes/circuits.js -> build/routes/circuits.js
2018-06-30T11:58:41.380720+00:00 app[web.1]: src/routes/stripe.js -> build/routes/stripe.js
2018-06-30T11:58:41.411474+00:00 app[web.1]: src/routes/users.js -> build/routes/users.js
2018-06-30T11:58:41.423692+00:00 app[web.1]: src/utils/parseErrors.js -> build/utils/parseErrors.js
2018-06-30T11:58:41.508066+00:00 heroku[web.1]: Process exited with status 0
2018-06-30T11:58:41.532442+00:00 heroku[web.1]: State changed from starting to crashed

这是我运行时的输出 Heroku local web

[OKAY] Loaded ENV .env File as KEY=VALUE Format
8:04:38 AM web.1 |  > [email protected] build /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 |  > npm run clean && npm run build-babel
8:04:38 AM web.1 |  > [email protected] clean /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 |  > rm -rf build && mkdir build
8:04:39 AM web.1 |  > [email protected] build-babel /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:39 AM web.1 |  > babel -d ./build ./src -s
8:04:39 AM web.1 |  src/index.js -> build/index.js
8:04:39 AM web.1 |  src/mailer.js -> build/mailer.js
8:04:39 AM web.1 |  src/models/Circuit.js -> build/models/Circuit.js
8:04:39 AM web.1 |  src/models/User.js -> build/models/User.js
8:04:39 AM web.1 |  src/routes/auth.js -> build/routes/auth.js
8:04:39 AM web.1 |  src/routes/circuits.js -> build/routes/circuits.js
8:04:39 AM web.1 |  src/routes/stripe.js -> build/routes/stripe.js
8:04:39 AM web.1 |  src/routes/users.js -> build/routes/users.js
8:04:39 AM web.1 |  src/utils/parseErrors.js -> build/utils/parseErrors.js
8:04:39 AM web.1 Exited Successfully

这是我的 package.json 文件:

{
  "name": "bookworm-api",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "test": "nodemon --exec babel-node -- src/index.js",
    "clean": "rm -rf build && mkdir build",
    "build-babel": "babel -d ./build ./src -s",
    "build": "npm run clean && npm run build-babel",
    "start": "npm run build && node ./build/index.js"
  },
  "engines": {
    "node": "9.4.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-eslint": "^8.2.3",
    "babel-preset-env": "^1.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-prettier": "^2.6.0",
    "nodemon": "^1.17.4"
  },
  "dependencies": {
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "bcrypt": "^2.0.1",
    "bluebird": "^3.5.1",
    "body-parser": "^1.18.2",
    "dotenv": "^5.0.1",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.2.1",
    "lodash": "^4.17.10",
    "mongodb": "^3.1.0",
    "mongoose": "^4.11.10",
    "mongoose-unique-validator": "^2.0.1",
    "nodemailer": "^4.6.4",
    "request-promise": "^4.2.2",
    "stripe": "^6.1.1",
    "uuid": "^3.2.1",
    "xml2js": "^0.4.19"
  }
}

这是我的 index.js 文件:

import express from 'express';
import path from 'path';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import Promise from 'bluebird';

import auth from './routes/auth';
import users from './routes/users';
import circuits from "./routes/circuits";
import stripe from './routes/stripe';

dotenv.config();
const app = express();
app.use(bodyParser.json());
mongoose.Promise = Promise;
mongoose.connect(
  process.env.MONGODB_URI || process.env.MONGODB_URL_DEV_LOCAL,
  {useMongoClient: true});

app.use('/api/auth', auth);
app.use('/api/users', users);
app.use('/api/circuits', circuits);
app.use('/api/stripe', stripe);

app.post('/api/auth', (req, res) => {
  res.status(400).json({ errors: {global: "Invalid Credentials" } });
});

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
})

var port = process.env.PORT || 8080

app.listen(port || 8080, function(){
  console.log("App is running on port " + port);
});

这是我的 Procfile

web: npm run build

我确定其他人遇到了这个问题,但我一直无法找到建议下一步采取什么措施的资源。如果您能将我指向相关资源或自己提供答案,将不胜感激!

霍里亚科曼

Procfile似乎被定义为在开始过程时正在构建东西。构建成功(返回 0),但随后进程停止,Heroku 认为这是一个糟糕的情况,因为 Web 服务器不应该停止。

您需要在 Heroku 中实际运行Web 服务器。类似的东西web: npm run start


虽然我会将构建和运行阶段分开。您应该在本地或构建机器(或构建服务,例如 Travis、Circle 等——它们也有 Heroku 集成)上进行构建,然后将编译的内容推送到 Heroku。所以Procfile只能是web: node ./build/index.js或类似的东西。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Node.js应用程序在本地主机上运行良好,但在Heroku上部署时显示错误

Heroku Node.js (express.js) 应用程序在本地运行,但在使用 MongoDB 时在 heroku 上失败

当我git merge时,Heroku不会重新部署我的应用程序

node.js应用程序可在本地运行,但在heroku上部署时会崩溃

我正在使用 node js 开发一个应用程序,它在本地运行良好,但在我尝试将其上传到 heroku 时崩溃,它说 cat find dotenv

应用程序错误 - 尽管我的应用程序在开发中运行良好,但在部署到 Heroku 后我收到一条错误消息

我的React前端无法调用我的node-express后端服务器,全栈应用已部署在heroku中

推送被拒绝,在 heroku 中部署时无法编译 Node.js 应用程序

将Node Express应用部署到服务React应用的Heroku

尝试在Heroku上部署Node.js / Express / Socket.io应用程序时出现应用程序错误

无法将我的node.js应用程序推送到Heroku

部署到heroku时,如何使我的node / socket.io应用使用正确的端口?

在 heroku 中部署 node.js / express / mongoDB ( with typescript )

我在 heroku 上部署了我的应用程序,但在运行 heroku 日志时出现此错误日志尾部“连接到数据库时出错”

将我的Rails应用程序部署到heroku时出现应用程序错误

Rails应用程序在本地运行,但在部署到Heroku时无法运行

Simple Flask应用程序可在本地运行,但是当我部署到heroku时崩溃

应用程序错误:我的 Flask-web-app 已在 Heroku 上成功部署,但在加载站点时收到应用程序错误

Node.js应用程序在Heroku中部署

部署到heroku的React / Node应用程序显示黑屏

无法在 Heroku 上部署 Node.js 应用程序

无法将我的 symfony 应用程序部署到 heroku

我的应用程序无法部署到 heroku

将Meteor应用程序部署到Heroku时出错-如何更改NODE版本

部署到heroku时,我的应用程序不断崩溃。我收到这个担心的应用程序错误主屏幕

部署的 Heroku 应用程序仅在刷新后才能工作(Node.js、Express.js、Jquery、Css、Html、TMDB API)

部署在 heroku 上的 React + Node + Express 应用程序显示一个空白页面,用于不匹配的 404 路由

我试图将我的ruby on rails应用程序部署到heroku,并且它正确部署

我正在嘗試將我的 node.js 應用程序部署到 heroku