reactjs – 在反应原生环境中要求未知模块“加密”

前端之家收集整理的这篇文章主要介绍了reactjs – 在反应原生环境中要求未知模块“加密”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用react-native编写一个简单的Twitter应用程序.使用 twit模块获取Twitter提要和流.下面是代码,它工作正常.但是,当包含在我的react-native应用程序中时,看到错误“需要未知模块”加密“”.依赖性似乎是myapp-> twit-> oauth-> crypto(那是节点v0.12.2的一部分).有什么建议让这个在react-native环境中工作?
  1. var Twit = require('twit')
  2. var T = new Twit({
  3. consumer_key:'',consumer_secret:'',access_token:'',access_token_secret:''
  4. })
  5. var filtered_tweets=[];
  6. var error;
  7. var isSuccess=false;
  8.  
  9. function getTweets(searchString){
  10. T.get('search/tweets',{q:searchString,count:100},getResponse);
  11. }
  12.  
  13. function getResponse(err,data,response){
  14. if(err) {
  15. handleGetErr(err);
  16. }
  17. handleGetData(data.statuses);
  18. }
  19.  
  20. function handleGetErr(err){
  21.  
  22. enter code here
  23.  
  24. error = err;
  25. }
  26.  
  27. function handleGetData(data){
  28. data.map(function(tweet){
  29. var twit={
  30. twit:tweet.id,created_at:tweet.created_at,text:tweet.text,retweet_count:tweet.retweet_count,favorite_count:tweet.favorite_count
  31. };
  32. filtered_tweets.push(twit);
  33. });
  34. console.log(filtered_tweets);
  35. isSuccess=true;
  36. }
  37. getTweets("@sahaswaranamam");
  38. module.exports = getTweets;

![附] [2]

加密模块是内置的Node模块; React Native在JavaScriptCore(在设备或模拟器上)和Chrome本身(使用Chrome调试时)运行JS,因此依赖于内置Node.js模块的模块将无法运行.有关详细信息,请参阅React Native文档的 the JavaScript Runtime section.

我不确定集成到React Native应用程序有多难,但Browserify等浏览器模块捆绑包通常具有核心Node.js模块的浏览器版本,如this one for crypto.

猜你在找的React相关文章