Javascript 希罗库;React部署成功,但出现应用程序错误

Javascript 希罗库;React部署成功,但出现应用程序错误,javascript,node.js,reactjs,express,heroku,Javascript,Node.js,Reactjs,Express,Heroku,我的构建和应用程序部署成功,但我的应用程序仍无法部署。我尝试过更改服务器端口、更新依赖项、重新部署、重建和重新提交。我不知道该怎么办 我已经尝试了我能想到的一切,任何帮助都将不胜感激我的服务器有问题吗?还是别的什么?救救我 我的服务器文件: import express from 'express'; import path from 'path'; import open from 'open'; /* eslint-disable no-console */ const PORT = 8

我的构建和应用程序部署成功,但我的应用程序仍无法部署。我尝试过更改服务器端口、更新依赖项、重新部署、重建和重新提交。我不知道该怎么办

我已经尝试了我能想到的一切,任何帮助都将不胜感激我的服务器有问题吗?还是别的什么?救救我

我的服务器文件:

import express from 'express';
import path from 'path';
import open from 'open';

/* eslint-disable no-console */

const PORT = 8080;
const app = express();

app.use(express.static('dist'));

app.get('*', function(req, res) {
    res.sendFile(path.join(__dirname, '../dist/index.html'));
});

app.listen(process.env.PORT || 5000);
我的Heroku日志:

2018-02-02T05:19:53.000000+00:00 app[api]: Build succeeded
2018-02-02T05:20:22.907775+00:00 heroku[web.1]: Restarting
2018-02-02T05:20:24.372493+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-02T05:20:26.106642+00:00 app[web.1]:
2018-02-02T05:20:26.106660+00:00 app[web.1]: > get_happy@1.0.0 prestart /app
2018-02-02T05:20:26.106662+00:00 app[web.1]: > babel-node ./tools/startMessage.js
2018-02-02T05:20:26.106664+00:00 app[web.1]:
2018-02-02T05:20:27.101748+00:00 app[web.1]: starting app in dev mode...
2018-02-02T05:20:27.126230+00:00 app[web.1]:
2018-02-02T05:20:27.126233+00:00 app[web.1]: > get_happy@1.0.0 start /app
2018-02-02T05:20:27.126235+00:00 app[web.1]: > npm-run-all --parallel open:src lint:watch test:watch
2018-02-02T05:20:27.126237+00:00 app[web.1]:
2018-02-02T05:20:27.758657+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-02T05:20:27.777930+00:00 app[web.1]:
2018-02-02T05:20:27.777950+00:00 app[web.1]: > get_happy@1.0.0 test:watch /app
2018-02-02T05:20:27.777952+00:00 app[web.1]: > npm run test -- --watch
2018-02-02T05:20:27.777954+00:00 app[web.1]:
2018-02-02T05:20:27.786621+00:00 app[web.1]:
2018-02-02T05:20:27.786624+00:00 app[web.1]: > get_happy@1.0.0 open:src /app
2018-02-02T05:20:27.786626+00:00 app[web.1]: > babel-node tools/srcServer.js
2018-02-02T05:20:27.786628+00:00 app[web.1]:
2018-02-02T05:20:27.813779+00:00 app[web.1]:
2018-02-02T05:20:27.813784+00:00 app[web.1]: > get_happy@1.0.0 lint:watch /app
2018-02-02T05:20:27.813786+00:00 app[web.1]: > npm run lint -- --watch
2018-02-02T05:20:27.813788+00:00 app[web.1]:
2018-02-02T05:20:28.134869+00:00 app[web.1]:
2018-02-02T05:20:28.134882+00:00 app[web.1]: > get_happy@1.0.0 test /app
2018-02-02T05:20:28.134885+00:00 app[web.1]: > mocha --reporter spec tools/testSetup.js"src/**/*.test.js" "--watch"
2018-02-02T05:20:28.134887+00:00 app[web.1]:
2018-02-02T05:20:28.207190+00:00 app[web.1]: > esw webpack.config.* src tools "--watch"
2018-02-02T05:20:28.207180+00:00 app[web.1]:
2018-02-02T05:20:28.207185+00:00 app[web.1]: > get_happy@1.0.0 lint /app
2018-02-02T05:20:28.207195+00:00 app[web.1]:
2018-02-02T05:20:28.420239+00:00 app[web.1]:
2018-02-02T05:20:29.434664+00:00 app[web.1]:
2018-02-02T05:20:29.434687+00:00 app[web.1]: > get_happy@1.0.0 prestart /app
2018-02-02T05:20:29.434689+00:00 app[web.1]: > babel-node ./tools/startMessage.js
2018-02-02T05:20:29.434691+00:00 app[web.1]:
2018-02-02T05:20:30.374402+00:00 app[web.1]: ✓ Clean (05:20:30)
2018-02-02T05:20:30.374420+00:00 app[web.1]:
2018-02-02T05:20:30.624534+00:00 app[web.1]:   SignUpPage via React Test Utils
2018-02-02T05:20:30.552948+00:00 app[web.1]:
2018-02-02T05:20:30.553304+00:00 app[web.1]:
2018-02-02T05:20:30.457582+00:00 app[web.1]: starting app in dev mode...
2018-02-02T05:20:30.479740+00:00 app[web.1]:
2018-02-02T05:20:30.479743+00:00 app[web.1]: > get_happy@1.0.0 start /app
2018-02-02T05:20:30.479745+00:00 app[web.1]: > npm-run-all --parallel open:src lint:watch test:watch
2018-02-02T05:20:30.479746+00:00 app[web.1]:
    ✓ renders first div842+00:00 app[web.1]:
2018-02-02T05:20:30.631440+00:00 app[web.1]:
2018-02-02T05:20:30.634135+00:00 app[web.1]:   First test
    ✓ should pass30.634139+00:00 app[web.1]:
2018-02-02T05:20:30.634141+00:00 app[web.1]:
2018-02-02T05:20:30.634142+00:00 app[web.1]:
2018-02-02T05:20:30.634144+00:00 app[web.1]:   2 passing (81ms)
2018-02-02T05:20:30.634146+00:00 app[web.1]:
2018-02-02T05:20:31.220493+00:00 app[web.1]:
2018-02-02T05:20:31.220506+00:00 app[web.1]: > get_happy@1.0.0 open:src /app
2018-02-02T05:20:31.220508+00:00 app[web.1]: > babel-node tools/srcServer.js
2018-02-02T05:20:31.220510+00:00 app[web.1]:
2018-02-02T05:20:31.239017+00:00 app[web.1]:
2018-02-02T05:20:31.239022+00:00 app[web.1]: > get_happy@1.0.0 test:watch /app
2018-02-02T05:20:31.239025+00:00 app[web.1]:
2018-02-02T05:20:31.239024+00:00 app[web.1]: > npm run test -- --watch
2018-02-02T05:20:31.254555+00:00 app[web.1]: > get_happy@1.0.0 lint:watch /app
2018-02-02T05:20:31.254557+00:00 app[web.1]: > npm run lint -- --watch
2018-02-02T05:20:31.254559+00:00 app[web.1]:
2018-02-02T05:20:31.254550+00:00 app[web.1]:
2018-02-02T05:20:31.702985+00:00 app[web.1]:
2018-02-02T05:20:31.703000+00:00 app[web.1]: > get_happy@1.0.0 test /app
2018-02-02T05:20:31.703002+00:00 app[web.1]: > mocha --reporter spec tools/testSetup.js"src/**/*.test.js" "--watch"
2018-02-02T05:20:31.703004+00:00 app[web.1]:
2018-02-02T05:20:31.767588+00:00 app[web.1]:
2018-02-02T05:20:31.767592+00:00 app[web.1]: > get_happy@1.0.0 lint /app
2018-02-02T05:20:31.767594+00:00 app[web.1]: > esw webpack.config.* src tools "--watch"
2018-02-02T05:20:31.767596+00:00 app[web.1]:
2018-02-02T05:20:32.060004+00:00 app[web.1]:
2018-02-02T05:20:34.387707+00:00 app[web.1]: webpack built e6aa51ace7cefd89072d in 5132ms
2018-02-02T05:20:34.389564+00:00 app[web.1]: ✓ Clean (05:20:34)
2018-02-02T05:20:34.389580+00:00 app[web.1]:
2018-02-02T05:20:34.594360+00:00 app[web.1]:
2018-02-02T05:20:34.594692+00:00 app[web.1]:
2018-02-02T05:20:34.651197+00:00 app[web.1]:   SignUpPage via React Test Utils
2018-02-02T05:20:34.658270+00:00 app[web.1]:
    ✓ should pass34.659761+00:00 app[web.1]:
    ✓ renders first div544+00:00 app[web.1]:
2018-02-02T05:20:34.660412+00:00 app[web.1]:   2 passing (66ms)
2018-02-02T05:20:34.658541+00:00 app[web.1]:   First test
2018-02-02T05:20:34.660524+00:00 app[web.1]:
2018-02-02T05:20:34.659878+00:00 app[web.1]:
2018-02-02T05:20:34.660221+00:00 app[web.1]:
2018-02-02T05:20:39.845456+00:00 app[web.1]: webpack built e6aa51ace7cefd89072d in 6512ms
2018-02-02T05:20:45.480480+00:00 app[web.1]: Error waiting for process to terminate: Nochild processes
2018-02-02T05:20:45.448861+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-02T05:20:45.556771+00:00 heroku[web.1]: Process exited with status 22
2018-02-02T05:21:27.875540+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web processfailed to bind to $PORT within 60 seconds of launch
2018-02-02T05:21:27.875691+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-02-02T05:21:28.025829+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-02T05:21:28.011800+00:00 heroku[web.1]: Process exited with status 137
2018-02-02T05:21:29.827718+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=roadtripadventuremap.herokuapp.com request_id=17fd46a1-817b-4501-9312-7bfe7a5a718d fwd="169.234.121.183" dyno= connect= service= status=503 bytes= protocol=https
2018-02-02T05:21:30.947465+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=roadtripadventuremap.herokuapp.com request_id=8a9a2659-55aa-44fc-9514-b0877b09a50a fwd="169.234.121.183" dyno= connect= service= status=503 bytes= protocol=https

根据您的项目,并参考本手册,了解正确的设置

看起来您的启动功能不是在npm start上运行的,因为它不会启动dist服务器。 由于heroku在默认情况下尝试运行npm start,所以它会像在开发环境中一样启动它

我会将package.json中的“脚本”更改为

"scripts": {
    "prestart": "babel-node ./tools/startMessage.js",
    "start-dev": "npm-run-all --parallel open:src lint:watch test:watch",
    "start": "node tools/distServer.js",
    "open:src": "babel-node tools/srcServer.js",
    "lint": "node_modules/.bin/esw webpack.config.* src tools",
    "lint:watch": "npm run lint -- --watch",
    "test": "mocha --reporter spec tools/testSetup.js \"src/**/*.test.js\"",
    "test:watch": "npm run test -- --watch",
    "clean-dist": "npm run remove-dist && mkdir dist",
    "remove-dist": "node_modules/.bin/rimraf ./dist",
    "build:html": "babel-node tools/buildHtml.js",
    "prebuild": "npm-run-all clean-dist test lint build:html",
    "build": "babel-node tools/build.js",
    "postbuild": "babel-node tools/distServer.js"
},
您还必须删除import语句才能在heroku服务器上工作,因此将distServer.js更改为

const express = require('express');
const path = require('path');
const open = require('open');

/* eslint-disable no-console */

const PORT = 8080;
const app = express();

app.use(express.static('dist'));

app.get('*', function(req, res) {
    res.sendFile(path.join(__dirname, '../dist/index.html'));
});

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

编辑。使用这些更改,我可以部署到测试heroku服务器,祝您好运。看起来是个有趣的项目