npm 安装:npm 错误! https://registry.npmjs.org/axios 处的无效 json 响应正文原因:JSON 输入的意外结束

npm install: npm ERR! invalid json response body at https://registry.npmjs.org/axios reason: Unexpected end of JSON input

我有一个 gatsby 投资组合应用程序,必须对其进行一些更新。然后从 github 克隆它并且必须安装依赖项。当我 运行 npm install 我有以下错误日志:

npm WARN ERESOLVE overriding peer dependency
npm WARN Found: eslint-plugin-flowtype@undefined
npm WARN node_modules/eslint-plugin-flowtype
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint-plugin-flowtype@"3.x || 4.x" from eslint-config-react-app@5.2.1
npm WARN node_modules/eslint-config-react-app
npm WARN   eslint-config-react-app@"^5.2.1" from gatsby@2.32.13
npm WARN   node_modules/gatsby
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: eslint-plugin-react@undefined
npm WARN node_modules/eslint-plugin-react
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint-plugin-react@"7.x" from eslint-config-react-app@5.2.1
npm WARN node_modules/eslint-config-react-app
npm WARN   eslint-config-react-app@"^5.2.1" from gatsby@2.32.13
npm WARN   node_modules/gatsby
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: eslint-plugin-react-hooks@undefined
npm WARN node_modules/eslint-plugin-react-hooks
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer eslint-plugin-react-hooks@"1.x || 2.x" from eslint-config-react-app@5.2.1
npm WARN node_modules/eslint-config-react-app
npm WARN   eslint-config-react-app@"^5.2.1" from gatsby@2.32.13
npm WARN   node_modules/gatsby
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: graphql@undefined
npm WARN node_modules/graphql
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^14.4.1" from express-graphql@0.9.0
npm WARN node_modules/express-graphql
npm WARN   express-graphql@"^0.9.0" from gatsby@2.32.13
npm WARN   node_modules/gatsby
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: graphql@undefined
npm WARN node_modules/gatsby-source-strapi/node_modules/graphql
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0" from express-graphql@0.6.12
npm WARN node_modules/gatsby-source-strapi/node_modules/express-graphql
npm WARN   express-graphql@"^0.6.6" from gatsby@1.9.279
npm WARN   node_modules/gatsby-source-strapi/node_modules/gatsby
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: graphql@undefined
npm WARN node_modules/gatsby-source-strapi/node_modules/gatsby/node_modules/graphql
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer graphql@"^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0" from graphql-relay@0.5.5
npm WARN node_modules/gatsby-source-strapi/node_modules/gatsby/node_modules/graphql-relay
npm WARN   graphql-relay@"^0.5.1" from gatsby@1.9.279
npm WARN   node_modules/gatsby-source-strapi/node_modules/gatsby
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/axios reason: Unexpected end of JSON input

我已经再次使用 npm cache clean --force 和 运行 npm install 清除了缓存,但我仍然有同样的错误....

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/axios reason: Unexpected end of JSON input

如果能帮我解决这个问题,我将不胜感激。

package.json 文件

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "gatsby": "^2.21.0",
    "gatsby-image": "^2.4.0",
    "gatsby-plugin-react-helmet": "^3.3.1",
    "gatsby-plugin-webfonts": "^1.1.3",
    "gatsby-plugin-sharp": "^2.6.0",
    "gatsby-plugin-sitemap": "^2.4.2",
    "gatsby-source-filesystem": "^2.3.0",
    "gatsby-source-strapi": "0.0.12",
    "gatsby-transformer-sharp": "^2.5.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-helmet": "^6.0.0",
    "react-icons": "^3.10.0",
    "react-markdown": "^4.3.1"
  },
  "devDependencies": {
    "prettier": "2.0.5"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

这不是您的问题。不是package.json的问题。在 ERR 中,URL https://registry.npmjs.org/axios(错误消息的最后一行)给出了一个有缺陷的 JSON 响应。请参见下图。 JSON 验证失败。他们必须解决这个问题。

尝试运行

npm cache clean --force
npm cache verify
yarn

或者尝试卸载然后重新安装。

编辑:

删除 node_modules 文件夹和 lock 文件。然后尝试 运行 yarn

如果您没有安装 yarn,请使用

安装
npm i -g yarn

使用

检查安装
yarn --version