【问题标题】:npm is failing to parse package.jsonnpm 无法解析 package.json
【发布时间】:2020-06-21 18:08:40
【问题描述】:

我是使用 npm 和节点的新手,我创建了一个带有 truffle unbox react 的 react 应用程序,它使用 npm init react-app。我已经尝试重新安装 npm 并清除缓存,但是当我运行 sudo npm start 时,我不断收到以下错误。

npm ERR! code EJSONPARSE
npm ERR! file /home/a/Documents/so/client/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token { in JSON at position 634 while parsing near '...rsion"
npm ERR! JSON.parse     ]
npm ERR! JSON.parse   }
npm ERR! JSON.parse }
npm ERR! JSON.parse 
npm ERR! JSON.parse {
npm ERR! JSON.parse "name": "mapboxAnd...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/a/.npm/_logs/2020-06-21T17_39_45_819Z-debug.log

我的 package.json 看起来像这样。

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "16.11.0",
    "react-dom": "16.11.0",
    "react-scripts": "3.2.0",
    "web3": "1.2.2"
  },
  "scripts": {
    "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"
    ]
  }
}

据我所知,package.json 只不过是 json。请帮助我理解这个错误。谢谢。

【问题讨论】:

    标签: javascript json npm truffle


    【解决方案1】:

    您的 package.json 是一个有效的 JSON 文件,错误在其他地方。 请您执行以下操作:

    1. 在没有 sudo 的情况下运行包,例如“npm start”而不是“sudo npm start”,你不应该以 root 身份运行你的包。
    2. 查看日志文件“/home/a/.npm/_logs/2020-06-21T17_39_45_819Z-debug.log”并发布更多详细信息。

    【讨论】:

      猜你喜欢
      • 2017-10-12
      • 2021-04-29
      • 2018-07-14
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 2021-05-12
      相关资源
      最近更新 更多