`

SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":fals

 
阅读更多

错误情况

执行 下面命令行时,报错

create-react-app my-react-app

npm错误日志如下

161 silly pacote version manifest for webpack@3.8.1 fetched in 116ms
162 silly resolveWithNewModule webpack@3.8.1 checking installable status
163 http fetch GET 304 https://registry.npm.taobao.org/sw-precache-webpack-plugin 155ms (from cache)
164 silly pacote version manifest for sw-precache-webpack-plugin@0.11.4 fetched in 156ms
165 silly resolveWithNewModule sw-precache-webpack-plugin@0.11.4 checking installable status
166 http fetch GET 304 https://registry.npm.taobao.org/eslint-plugin-react 406ms (from cache)
167 silly pacote version manifest for eslint-plugin-react@7.4.0 fetched in 412ms
168 silly resolveWithNewModule eslint-plugin-react@7.4.0 checking installable status
169 http fetch GET 304 https://registry.npm.taobao.org/case-sensitive-paths-webpack-plugin 598ms (from cache)
170 silly pacote version manifest for case-sensitive-paths-webpack-plugin@2.1.1 fetched in 599ms
171 silly resolveWithNewModule case-sensitive-paths-webpack-plugin@2.1.1 checking installable status
172 silly pacote http://registry.npm.taobao.org/fsevents/download/fsevents-1.1.2.tgz extracted to /var/folders/09/wz7n0jm57595m97_zpcl7h6m0000gn/T/npm-2400-75ffb0fc/unpack-e2104430 by content address 367ms
173 silly addBundled read tarball
174 silly cleanup remove extracted module
175 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar'
175 verbose stack     at JSON.parse (<anonymous>)
175 verbose stack     at parseJson (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/node_modules/json-parse-better-errors/index.js:7:17)
175 verbose stack     at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/body.js:96:50)
175 verbose stack     at <anonymous>
175 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
176 verbose cwd /Users/shanshanxue/Documents/workspace/my-react-app
177 verbose Darwin 16.4.0
178 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "--save" "--save-exact" "--loglevel" "error" "react" "react-dom" "react-scripts"
179 verbose node v9.2.0
180 verbose npm  v5.5.1
181 error Unexpected end of JSON input while parsing near '...ttachment":false,"tar'
182 verbose exit [ 1, true ]

解决办法:

设置npm代理地址,命令如下:

npm config set registry http://registry.cnpmjs.org

之前一直用的淘宝npm代理

npm config set registry https://registry.npm.taobao.org

切换回来,就不报错。详细起因不明白。

补充:把npm版本降级,实测可以解决,可能5.0以上版本有微妙的问题

node v9.2.0
npm  v5.5.1

上面是我本机当前的环境信息,可以把npm降级后试试,命令如下

npm i -g npm@4

再补充

使用 yarn 安装
npm i -g yarn
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics