部署后Heroku出现应用程序错误

时间:2018-08-14 12:56:53

标签: node.js reactjs heroku npm yarnpkg

成功部署我的应用程序后,我单击“打开应用程序”,然后看到此错误:

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

链接错误https://site-web-france.herokuapp.com/

但是它可以在本地环境中使用yarn dev cli正常工作

package.json用于后端应用程序:

{
  "name": "site-web-france",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build",
    "client": "cd client && yarn start",
    "server": "nodemon server.js",
    "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\"",
    "dev:server": "cd client && yarn build && cd .. && yarn start",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "mongodb": "^3.1.1",
    "mongoose": "^5.2.6",
    "react-scripts": "^1.1.4"
  },
  "devDependencies": {
    "concurrently": "^3.5.0"
  }
}

我认为这个问题是由于“纱线”引起的,您怎么看?

教程遵循: https://medium.freecodecamp.org/how-to-make-create-react-app-work-with-a-node-backend-api-7c5c48acb1b0

1 个答案:

答案 0 :(得分:1)

确保应用程序端口不是 硬编码,例如:

app.listen(3000, ...)

它可能会导致Heroku问题。而是尝试使用环境变量PORT

app.listen(process.env.PORT || 3000, ...)

希望有帮助!