react-native create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理
SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar'
错误情况
执行 下面命令行时,报错
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
人这一辈子没法做太多的事情,
所以每一件都要做得精彩绝伦。
你的时间有限,
所以不要为别人而活。
不要被教条所限,
不要活在别人的观念里。
不要让别人的意见左右自己内心的声音。
最重要的是,
勇敢的去追随自己的心灵和直觉,
只有自己的心灵和直觉才知道你自己的真实想法,
其他一切都是次要。
工作是生活的一部分,所以工作不能全部占用于生活。