简体   繁体   English

npm 无法解析 package.json

[英]npm is failing to parse package.json

I'm new to using npm and node I created a react app with truffle unbox react which uses npm init react-app.我是使用 npm 和节点的新手,我使用 truffle unbox react 创建了一个反应应用程序,它使用 npm init react-app。 I have tried reinstalling npm and clearing the cache but I keep getting the following error when I run sudo npm start.我尝试重新安装 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

My package.json looks like this.我的 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"
    ]
  }
}

As far as I can tell package.json is nothing but json.据我所知,package.json 只不过是 json。 Please help me understand this error.请帮助我理解这个错误。 Thankyou.谢谢你。

Your package.json is a valid JSON file, the error is somewhere else.您的 package.json 是有效的 JSON 文件,错误在其他地方。 Can you please do the below:你能做到以下几点:

  1. run the package without sudo, eg "npm start" instead of "sudo npm start", you shouldn't run your packages as root.在没有 sudo 的情况下运行 package,例如“npm start”而不是“sudo npm start”,你不应该以 root 身份运行你的包。
  2. have a look at the log file "/home/a/.npm/_logs/2020-06-21T17_39_45_819Z-debug.log" and post more details.查看日志文件“/home/a/.npm/_logs/2020-06-21T17_39_45_819Z-debug.log”并发布更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM