如何解决Heroku无法部署我的React应用程序的错误?

时间:2020-04-27 05:43:37

标签: node.js reactjs heroku npm

我创建了新的heroku应用程序,并首先推送了我的react应用程序,但没有出现错误,但是尝试加载到heroku时崩溃了。

package.json 文件:

    {
      "name": "covid-react",
      "version": "0.1.0",
      "private": true,
      "engines": {
        "node": "12.14.0",
        "npm": "6.13.4"
      },
      "dependencies": {
        "@fortawesome/fontawesome": "^1.1.8",
        "@fortawesome/fontawesome-svg-core": "^1.2.28",
        "@fortawesome/free-solid-svg-icons": "^5.13.0",
        "@fortawesome/react-fontawesome": "^0.1.9",
        "@material-ui/core": "^4.9.11",
        "@testing-library/jest-dom": "^4.2.4",
        "@testing-library/react": "^9.5.0",
        "@testing-library/user-event": "^7.2.1",
        "axios": "^0.19.2",
        "chart.js": "^2.9.3",
        "classnames": "^2.2.6",
        "react": "^16.13.1",
        "react-chartjs-2": "^2.9.0",
        "react-countup": "^4.3.3",
        "react-dom": "^16.13.1",
        "react-scripts": "3.4.1",
        "serve": "11.3.0"
      },
      "scripts": {
        "predeploy": "npm run build",
        "deploy": "serve -s build",
        "postdeploy": "now alias -A ./build/now.json",
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"    
      },
      "eslintConfig": {
        "extends": "react-app"
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not ie <= 11",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      }
    }

Procfile

网络:npm运行部署

Heroku日志

2020-04-27T06:24:23.689579+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-27T06:24:23.608647+00:00 app[web.1]: npm ERR! missing script: deploy
2020-04-27T06:24:23.617094+00:00 app[web.1]: 
2020-04-27T06:24:23.617388+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-04-27T06:24:23.617531+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-04-27T06_24_23_609Z-debug.log
2020-04-27T06:24:24.000000+00:00 app[api]: Build succeeded
2020-04-27T06:24:29.460961+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=covid19tracker-sid.herokuapp.com request_id=3f536ce1-d49b-4f04-990d-4fb1ef5ef39e fwd="142.117.23.250" dyno= connect= service= status=503 bytes= protocol=https
2020-04-27T06:24:29.843959+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=covid19tracker-sid.herokuapp.com request_id=97a80763-71d6-4dbf-9aa1-e4ecbc87a7d5 fwd="142.117.23.250" dyno= connect= service= status=503 bytes= protocol=https

Heroku将应用程序状态记录为崩溃。我尝试更改package.json react-script开始并使用deploy命令添加Procfile,但应用程序仍然没有显示。 Heroku应用程序运行一段时间后会在崩溃中显示日志。

更新:我通过添加此代码来做到这一点

"scripts": {
    "dev": "react-scripts start",
    "deploy": "serve -s build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "heroku-postbuild": "npm run build"    
  },

0 个答案:

没有答案