Heroku应用程序崩溃:at =错误代码= H10 desc =“应用程序崩溃”方法=获取路径=“ /”

时间:2020-05-26 06:24:36

标签: node.js reactjs express heroku mern

**我一直在尝试将自己的MERN应用上传到Heroku,并一直收到这些错误代码。该Web应用程序将在我的本地主机上运行,​​但是当我尝试将其上传到heroku时,该应用程序立即失败。我对使用MERN堆栈比较陌生,并且正在尝试弄清楚如何正确地将应用程序上传到Heroku。 *

2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here

heroku日志--tail

2020-05-26T04:54:22.910425+00:00 app[api]: Initial release by user woodjack191@gmail.com
2020-05-26T04:54:22.910425+00:00 app[api]: Release v1 created by user woodjack191@gmail.com
2020-05-26T04:54:23.096112+00:00 app[api]: Enable Logplex by user woodjack191@gmail.com
2020-05-26T04:54:23.096112+00:00 app[api]: Release v2 created by user woodjack191@gmail.com
2020-05-26T04:58:40.000000+00:00 app[api]: Build started by user woodjack191@gmail.com
2020-05-26T04:59:47.263635+00:00 app[api]: Deploy 7d333fc9 by user woodjack191@gmail.com
2020-05-26T04:59:47.263635+00:00 app[api]: Release v3 created by user woodjack191@gmail.com
2020-05-26T04:59:47.283454+00:00 app[api]: Scaled to web@1:Free by user woodjack191@gmail.com
2020-05-26T04:59:54.000000+00:00 app[api]: Build succeeded
2020-05-26T04:59:56.664155+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T04:59:59.487422+00:00 app[web.1]:
2020-05-26T04:59:59.487434+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T04:59:59.487434+00:00 app[web.1]: > react-scripts start
2020-05-26T04:59:59.487435+00:00 app[web.1]:
2020-05-26T05:00:02.028314+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.10.22/
2020-05-26T05:00:02.028881+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:02.029021+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:02.029167+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:02.029361+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:02.029362+00:00 app[web.1]: 
2020-05-26T05:00:02.141290+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:02.315545+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:02.318095+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:00:09.983236+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:00:12.651901+00:00 app[web.1]: 
2020-05-26T05:00:12.651922+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:00:12.651923+00:00 app[web.1]: > react-scripts start
2020-05-26T05:00:12.651923+00:00 app[web.1]:
2020-05-26T05:00:16.868981+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.178.250/
2020-05-26T05:00:16.869628+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:16.869783+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:16.869929+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:16.870239+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:16.870241+00:00 app[web.1]: 
2020-05-26T05:00:17.013391+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:17.057205+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:11:05.245937+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:14.187854+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:16.938860+00:00 app[web.1]:
2020-05-26T05:11:16.938887+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:11:16.938887+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:16.938887+00:00 app[web.1]: 
2020-05-26T05:11:18.963210+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.19.50.2/
2020-05-26T05:11:18.963807+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:18.963915+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:18.964030+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:18.964316+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:18.964319+00:00 app[web.1]: 
2020-05-26T05:11:19.093706+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:19.137119+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:11:19.140236+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:26.041885+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:28.043546+00:00 app[web.1]: 
2020-05-26T05:11:28.043558+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:11:28.043558+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:28.043559+00:00 app[web.1]:
2020-05-26T05:11:29.727646+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.16.13.198/
2020-05-26T05:11:29.727983+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:29.728062+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:29.728128+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:29.728294+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:29.728295+00:00 app[web.1]:
2020-05-26T05:11:29.800107+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:29.835462+00:00 heroku[web.1]: State changed from starting to crashed

server.js文件

const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path')
const app = express();
require('./database');

app.use(bodyParser.json());
app.use(cors());

// API
const users = require('./api/users');
app.use('/api/users', users);

app.use(express.static(path.join(__dirname, '../build')))
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '../build'))
})

const port = process.env.PORT || 5000;
app.listen(port, () => {
    console.log(`Server started on port ${port}`);
});

package.json文件

{
  "name": "my-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "body-parser": "^1.19.0",
    "bootstrap": "^4.5.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "mongoose": "^5.9.15",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "node backend/server.js",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install npm && run build",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:5000",
  "engines": {
    "node": "10.16.0"
  }
}

2 个答案:

答案 0 :(得分:0)

这可以通过两种方式解决:

1)如果您忘记设置启动脚本,通常会抛出此错误! Heroku要求Procfile(如果您想覆盖Heroku的默认启动命令)与您的应用程序文件一起上传。

Procfile的内容应这样:

web: node index.js(即为您的应用程序指定要运行的节点命令)

2)如果您不想上传Procfile,则可以在"scripts"的{​​{1}}(已经完成)中指定命令,同时还需要添加{{1 }}中的package.json

您还使用了"build":"webpack"来代替package.json脚本……所以实际上它必须起作用!但是您可以尝试上述两种方法之一,然后尝试对其进行调试(希望其中一种肯定可以工作)!

答案 1 :(得分:0)

将此添加到您的server.js:

var distDir = __dirname + "/dist/";

app.use(express.static(distDir));