我是靠谱客的博主 超级柜子,这篇文章主要介绍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:AndroidToolsReactNativeProjectReactNativeOne-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:UsersyuepaiAppDataRoamingnpm-cache_git-remotesgit-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:AndroidToolsReactNativeProjectReactNativeOne-masternode_modu
les.stagingreact-native-viewpager-05999a08
npm ERR! code EPERM
npm ERR! errno -4048

解决方法:
从网上搜索到一个解决方法,是因为npm缓存目录去缓存了个 _git-remotes 目录,删除再继续执行install即可
Windows路径:C:UsersyuepaiAppDataRoamingnpm-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,出现如下信息提示就说明添加成功了。
这里写图片描述

最后

以上就是超级柜子最近收集整理的关于React Native引入第三方库的全部内容,更多相关React内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部