Search code examples
jsonreactjsgithub-pages

ReactJs Deploying to Github Page Ejsonparse Error


Trying to deploy my reactJs into github pages followed this guide , installed gh-pages, whenever I added

"predeploy": "npm run build",
"deploy": "gh-pages -d build",

into my package.json I couldnt run npm start or npm run deploy it will give me the following error

also tried

npm cache clean --force
[rogerhfcheng@rogerlinux Cubing-Timer]$ npm run deploy
npm ERR! file /home/rogerhfcheng/Cubing-Timer/package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token } in JSON at position 505 while parsing near '...t-scripts eject",
npm ERR! JSON.parse   },
npm ERR! JSON.parse   "eslintConfig":...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

my package.json file

{
  "name": "my-app",
  "homepage": "https://xxx.github.io/xxx",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "gh-pages": "^2.0.1",
    "pretty-ms": "^5.0.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "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"
    ]
  }
}

Solution

  • There is a comma after eject script that shouldn't be there

    it should be

        "eject": "react-scripts eject"
    

    instead of

        "eject": "react-scripts eject",
    

    In JSON ther shouldn't be a comma after the last key-value pair in an object. You can use an extension to check and pretty print your JSON. Also there are online options to do this like JSON validator