npm 安装 npm install -g create-react-app 时报错,以及create-react-app my-app 时报错(神奇)

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
参考

https://segmentfault.com/q/1010000011955664

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值