【发布时间】:2019-08-14 15:00:07
【问题描述】:
尝试使用 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 就会成功 - 但当然该项目无法运行。
我使用的是节点 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