React Native引入第三方库

推荐一个React Native 项目常用的第三方组件博客 http://www.jianshu.com/p/d9cd9a868764#

系统要求
完成的React Native开发环境
安装rnpm【注意: rnpm需要node 4.1+】
“rnpm”是一个社区项目,可以提供原生依赖的自动链接。

npm install rnpm -g

添加库
使用CMD窗口进入react native项目的根目录,输入命令: npm install [第三方库] –save, 如果没有–save只是添加库,不会添加依赖。执行成功后 库会自动添加到项目根目录的node_modules文件夹里
如:[npm install react-native-toast –save]

删除库
如果没有–save只是删除库,不会删除依赖
如:[npm uninstall react-native-toast –save]

可能遇到的问题:
我在添加库【react-native-viewpager】(https://github.com/race604/react-native-viewpager.git)时遇到一个报错信息

D:\AndroidTools\ReactNativeProject\ReactNativeOne-master>npm install react-nativ
e-viewpager --save

npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config -
-get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:211:12)
npm WARN addRemoteGit     at emitTwo (events.js:106:13)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit     at maybeClose (internal/child_process.js:885:16)
npm WARN addRemoteGit     at Socket.<anonymous> (internal/child_process.js:334:1
1)
npm WARN addRemoteGit     at emitOne (events.js:96:13)
npm WARN addRemoteGit     at Socket.emit (events.js:188:7)
npm WARN addRemoteGit     at Pipe._handle.close [as _onclose] (net.js:501:12)
npm WARN addRemoteGit  git://github.com/lipeiwei-szu/react-native-viewpager.git
resetting remote C:\Users\yuepai\AppData\Roaming\npm-cache\_git-remotes\git-gith
ub-com-lipeiwei-szu-react-native-viewpager-git-a8d9ef93 because of error: { Erro
r: Command failed: git -c core.longpaths=true config --get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:211:12)
npm WARN addRemoteGit     at emitTwo (events.js:106:13)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit     at maybeClose (internal/child_process.js:885:16)
npm WARN addRemoteGit     at Socket.<anonymous> (internal/child_process.js:334:1
1)
npm WARN addRemoteGit     at emitOne (events.js:96:13)
npm WARN addRemoteGit     at Socket.emit (events.js:188:7)
npm WARN addRemoteGit     at Pipe._handle.close [as _onclose] (net.js:501:12)
npm WARN addRemoteGit   killed: false,
npm WARN addRemoteGit   code: 1,
npm WARN addRemoteGit   signal: null,
npm WARN addRemoteGit   cmd: 'git -c core.longpaths=true config --get remote.ori
gin.url' }
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\node.exe" "D:\\Program Files (x8
6)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "react-native-viewpage
r" "--save"
npm ERR! node v7.3.0
npm ERR! npm  v3.10.10
npm ERR! path D:\AndroidTools\ReactNativeProject\ReactNativeOne-master\node_modu
les\.staging\react-native-viewpager-05999a08
npm ERR! code EPERM
npm ERR! errno -4048

解决方法:
从网上搜索到一个解决方法,是因为npm缓存目录去缓存了个 _git-remotes 目录,删除再继续执行install即可
Windows路径:C:\Users\yuepai\AppData\Roaming\npm-cache_git-remotes

如果没有设置git代理 可能还是无法下载成功

设置代理
在Git窗口中输入如下命令

git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080

取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

再次执行命令npm install react-native-viewpager –save,出现如下信息提示就说明添加成功了。
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值