当尝试使用create-react-app模块创建一个React应用时,我遇到一个非常奇怪的错误。在我的计算机上,重新创建错误非常容易:
npx create-react-app test-project --typescript
该项目运行正常。但是,如果我删除node_modules文件夹并执行以下操作:
npm install
我收到此错误:
npm install
npm WARN deprecated flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
npm WARN deprecated left-pad@1.3.0: 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"
]
}
}
答案 0 :(得分:0)
我通过运行
解决了这个问题npm cache clean --force
但是,如果要在取消整个缓存之前检查它是否可行,则可以执行以下操作:
npm install --cache /tmp/empty-cache
它强制npm不使用缓存。
答案 1 :(得分:0)
我克隆了您的package.json,并且npm install
工作正常
使用节点v11.14.0和npm 6.7.0
答案 2 :(得分:0)
我试图清除此问题以在节点v12.8.1上使用。
但是我解决不了。
最后,我将节点版本降级为10.16.3 LTS。 :(
如果要使用没有npm错误的'create-react-app',只需使用节点版本 10.16.3 LTS。