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

免责声明:文章转载自《react-native create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇java过滤特殊字符的正则表达式docker中文乱码问题解决下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

webpack4系列之 【2. 踩坑--webpack 2.x升级至4.x】

一.安装webpack-cli,webpack@4.26.1 1.npm install webpack-cli -D 2.npm install webpack@4.26.1 -D 二.踩坑 执行npm run dev报错 1./Users/lily/ForWork/forBMSys/bm-fe/node_modules/html-webpack-plu...

‎Cocos2d-x 学习笔记(15.1) EventDispatcher

EventDispatcher对监听器进行管理,围绕着监听器工作。可以添加、删除、暂停/恢复监听器、分发事件到监听器。 1. 一些成员 /** 把ListenerID和同ID监听器的容器对应 */ std::unordered_map<EventListener::ListenerID, EventListenerVector*>...

Nginx 部署 单页面应用 + nodejs api 应用 最佳实践

假定你的域名是 xxx.com 如果没有域名 则使用你的服务器 ip 现代前端框架打包后基本会将文件放在 /dist 目录下,通常肯定会有一个index.html的文件 /dist/index.html 然后你需要把打包文件上传到服务器,假如你上传到了 "/var/www/xxx.com/web/" 配置 nginx 添加一个 server块 代理静态...

Nodejs介绍及npm工具使用

一、Nodejs介绍   Nodejs英文网:https://nodejs.org/en/   Nodejs中文网:http://nodejs.cn/ Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。 Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。 Node.js 的包管理器 npm,...

nodejs获取文件信息,判断是文件或目录

var stat = fs.statSync(filename); console.log(stat) 输出 {  dev: 0, ino: 0, mode: 33206, nlink: 1, uid: 0, gid: 0, rdev: 0, size: 1747, atime: Tue, 03 Jan 2...

Linux下Nodejs安装(完整详细)

node下载地址: http://nodejs.cn/download/ 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码,一种是编译后的文件。我就是按照网上源码的安装方式去操作编译后的文件,结果坑了好久好久。   (一) 编译好的文件     简单说就是解压后,在bin文件夹中已经存在node以及npm,如果你进入到对应文...