如何使用npm解决此常见的“无法解析json”问题?

时间:2018-11-07 23:23:49

标签: node.js json npm

npm经常出现问题,一段时间后,在React项目文件夹中运行npm start命令,该问题就会发生。

我得到几行日志,包括“无法解析json”和“ package.json必须是实际的JSON,而不仅仅是Javascript”。

在几周不使用后我开始处理该项目之后,问题总是会发生,我的package.json文件似乎很好,这是一个例子

{
  "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",
  }
}

另一个:

{
  "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"
  }
}

我尝试通过npm uninstall卸载npm,但遇到了同样的错误,同样,删除节点模块文件也无济于事(目的是重新安装它)。

那该问题的原因是什么以及如何解决?

1 个答案:

答案 0 :(得分:1)

错误的行是:

    "redux": "^4.0.0",

    "eject": "react-scripts eject",

与JavaScript不同,JSON对象的最后一个键值对中不允许使用逗号结尾。