npm 安装 npm install -g create-react-app 时报错
报错信息:
0 info it worked if it ends with ok
1 verbose cli [ 'D:\\path\\nodejs\\node.exe',
1 verbose cli 'D:\\path\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'express',
1 verbose cli '-g' ]
2 info using npm@6.4.1
3 info using node@v10.13.0
4 verbose npm-session 51984e7edf553c3d
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://registry.npmjs.org/express 54507ms attempt #2
8 silly fetchPackageMetaData error for express@latest Unexpected end of JSON input while parsing near '...rser":"0.0.4","mkdirp'
9 timing stage:rollbackFailedOptional Completed in 0ms
10 timing stage:runTopLevelLifecycles Completed in 54653ms
11 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...rser":"0.0.4","mkdirp'
11 verbose stack at JSON.parse (<anonymous>)
11 verbose stack at parseJson (D:\path\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
11 verbose stack at consumeBody.call.then.buffer (D:\path\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
11 verbose stack at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd C:\Users\Administrator
13 verbose Windows_NT 10.0.16299
14 verbose argv "D:\\path\\nodejs\\node.exe" "D:\\path\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "express" "-g"
15 verbose node v10.13.0
16 verbose npm v6.4.1
17 error Unexpected end of JSON input while parsing near '...rser":"0.0.4","mkdirp'
18 verbose exit [ 1, true ]
使用npm install -g cnpm –registry=https://registry.npm.taobao.org
安装淘宝的cnpm
然后就可以了。
但是,创建工程create-react-app my-app 又报错
E:\react>npx create-react-app my-react
Creating a new React app in E:\react\my-react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Unexpected end of JSON input while parsing near '...,"dist":{"integrity":'
npm ERR! A complete log of this run can be found in:
npm ERR! D:\path\nodejs\node_cache\_logs\2018-11-20T17_57_24_979Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my-react/ from E:\react
Done.
然后将代理还原回来后就又可以了,命令如下:
npm config set registry http://registry.cnpmjs.org