create-react-app建立項目報錯SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":fa

SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar'

錯誤狀況

執行 下面命令行時,報錯node

create-react-app my-react-app

npm錯誤日誌以下react

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代理地址,命令以下:webpack

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

以前一直用的淘寶npm代理web

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

切換回來,就不報錯。詳細原由不明白。npm

補充:把npm版本降級,實測能夠解決,可能5.0以上版本有微妙的問題

node v9.2.0
npm  v5.5.1

上面是我本機當前的環境信息,能夠把npm降級後試試,命令以下

npm i -g npm@4

再補充

使用 yarn 安裝
npm i -g yarn
相關文章
相關標籤/搜索