无法在全新的create-react-app上运行npm install

问题描述 投票:0回答:3

尝试使用create-react-app模块创建React应用时,我遇到一个非常奇怪的错误。 在我的计算机上,重新创建错误非常容易:

npx create-react-app test-project --typescript

该项目运行良好。 但是,如果我删除node_modules文件夹并执行以下操作:

npm install

我收到此错误:

 npm install
    npm WARN deprecated [email protected]: I wrote this module a very long time ago; you should use something else.
    npm WARN deprecated [email protected]: use String.prototype.padStart()
    npm ERR! Unexpected end of JSON input while parsing near '...3s4pkvleO6z4pcCFRth5v'

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/computer/.npm/_logs/2019-08-14T14_44_36_086Z-debug.log

有趣的是,如果我从package.json文件中删除了“ react-scripts”,则npm install会成功完成-但是,该项目当然无法正常工作。

我正在使用Node 12.8.0。 这是package.json文件:

{
  "name": "test-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "24.0.17",
    "@types/node": "12.7.1",
    "@types/react": "16.9.1",
    "@types/react-dom": "16.8.5",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-scripts": "3.1.1",
    "typescript": "3.5.3"
  },
  "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"
    ]
  }
}
reactjs npm npm-install
3个回答
0
投票

我通过运行解决了这个问题

npm cache clean --force

但是,如果要在取消整个缓存之前检查它是否可行,则可以执行以下操作:

npm install --cache /tmp/empty-cache

它强制npm不使用缓存。


0
投票

我使用节点v11.14.0和npm 6.7.0克隆了您的package.json和npm install工作正常


0
投票

我试图清除此问题以在节点v12.8.1上使用。

但我无法解决。

最后,我将节点版本降级为10.16.3 LTS。 :(

如果要使用没有npm错误的'create-react-app',只需使用节点版本10.16.3 LTS。

© www.soinside.com 2019 - 2024. All rights reserved.