0

I have a frequent problem with npm, it occurs when running npm start command in a react project folder after some time not working with that project.

I get several lines of log include 'Failed to parse json' and 'package.json must be actual JSON, not just Javascript'.

The problem always happen after i get to deal with the project after some weeks of no-use, my package.json file seems fine and this is an example

{
  "name": "carzyGame",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-scripts": "1.1.4",
    "redux": "^4.0.0",
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
  }
}

another one:

{
  "name": "neighborhood",
  "version": "0.1.0",
  "private": true,
  "predeploy": "npm run build",
  "deploy": "gh-pages -d build" 
  "dependencies": {
    "escape-string-regexp": "^1.0.5",
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-foursquare": "^1.0.3",
    "react-scripts": "1.1.4",
    "sort-by": "^1.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

I tried to uninstall npm by npm uninstall and i got the same error, also removing node modules file could not help (the purpose is to re-install it).

So what is the reason of that problem and how to solve it?

1 Answer 1

1

The faulty lines are:

    "redux": "^4.0.0",

    "eject": "react-scripts eject",

Unlike in JavaScript, a trailing comma is not allowed in the last key-value pair of a JSON object.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, i have edited the post with another project package.json file content, it does not contain the trailing comma and still returns the same error??
You missed the comma after "deploy": "gh-pages -d build".
I would recommend using a JSON validator to diagnose these errors. I use stedolan.github.io/jq - when I pasted your JSON into it I got the error "parse error: Expected separator between values at line 7, column 16" which is pretty explicit about what the problem is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.