rbren / rss-parser

A lightweight RSS parser, for Node and the browser
MIT License
1.38k stars 209 forks source link

error in android and ios on run time with React Native #174

Open mhhonline opened 4 years ago

mhhonline commented 4 years ago

Greetings,

I am using the lib on react native project. it is working fine on the browser (chrome) on android and ios, it is throwing an error ..

The package at "node_modules/rss-parser/lib/parser.js" attempted to import the Node standard library module "http". It failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/workflow/using-libraries/#using-third-party-libraries

Implementation:

import * as rssParser from 'rss-parser';
....
const fetchRssData = async () => {
    setIsLoading(true);
    // console.log(url);
    // TODO check the best solution https://wanago.io/2018/11/05/cors-cross-origin-resource-sharing/
    const CORS_PROXY = 'https://cors-anywhere.herokuapp.com/';
    let parser = new rssParser();
    (async () => {
      let feed = await parser.parseURL(CORS_PROXY + url);
      // get the title and update the page title
      console.log(feed.items?.length);
      const l = feed.items?.length;

      let data = new Array();
      if (l && l > 0) {
        setData(feed.items);
      }
      setIsLoading(false);
      setIsRefreshing(false);
    })();
  };
"rss-parser": "^3.9.0"

thanks

mhhonline commented 4 years ago

Greetings,

No input. I need your support

rbren commented 4 years ago

You can try the solutions found here: https://github.com/rbren/rss-parser/issues/53

I don't know enough about native React to be very helpful here.