React app runs locally, crashes when on Heroku error code=H10

前端 未结 5 1626
醉酒成梦
醉酒成梦 2020-12-16 18:26

The app runs fine after an \'npm start\' in windows, but when I pull from github into Heroku I just get an error.

package.json:

{
  \"name\": \"tic         


        
相关标签:
5条回答
  • 2020-12-16 18:50

    Just npm i serve to install serve then or you could use yarn instead of npm

    You can change your scripts in package.json file, it seemed to be caused by update by react.

    "scripts": {
    "dev": "react-scripts start",
    "start": "serve -s build",
    "build": "react-scripts build",
    "heroku-postbuild": "npm run build"}
    

    Hope it fixes your problem.

    0 讨论(0)
  • 2020-12-16 18:55

    Heroku doesnt install devdependencies by default:. https://devcenter.heroku.com/articles/nodejs-support. Either set your react-scripts module to always install or turn off production mode on Heroku.

    0 讨论(0)
  • 2020-12-16 19:05

    I face the same problem, it has worked for me.

    add "serve" to application.

    example: npm add serve or yarn add serve

    after change scripts in package.json

    "scripts": {
      "dev": "react-scripts start",
      "start": "serve -s build",
      "build": "react-scripts build",
      "heroku-postbuild": "npm run build"
    }
    
    0 讨论(0)
  • 2020-12-16 19:07

    I had the same problem, but the solution above did not work for my react app in Heroku. I have updated the build pack to create-react-app, and it worked for me.

    heroku buildpacks:set mars/create-react-app

    0 讨论(0)
  • 2020-12-16 19:08

    1.) npm install serve --save or yarn install serve --save in your terminal

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

    2.) copied the above code in place of previous code "scripts" in my package.json file

    3.) git commit -am "new update"

    4.) git push heroku master

    • Note: the common problem is missing the first step.
    0 讨论(0)
提交回复
热议问题