question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I use `cheerio` in `react native`?

See original GitHub issue

I like the cheerio library. I want to use cheerio in react native, but it didn’t work

import cio from 'cheerio';
Loading dependency graph, done.
error: bundling: UnableToResolveError: Unable to resolve module `events` from `G:\React-Native\test\node_modules\htmlparser2\lib\Parser.js`: Module dop or in these directories:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
Lizhoohcommented, Jul 27, 2017

@niocncn One of the libraries helped me, look https://github.com/oyyd/cheerio-without-node-native

No errors, can correctly parse.

import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import cio from 'cheerio-without-node-native';

export default class App extends Component {
    constructor(props) {
        super(props);
        this.$ = cio.load('<p class="hello" style="color: red">Hello world</p>');
    }
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.text}>{this.$('.hello').text()}</Text>
                <Text style={styles.text}>{this.$('.hello').attr('style')}</Text>
            </View>
        );
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
    },
    text: {
        fontSize: 30
    }
});
6reactions
LeoAsocommented, Jul 6, 2020

You can install react-native-cheerio but pretend that it’s cheerio.

yarn add cheerio@npm:react-native-cheerio && yarn add --dev @types/cheerio

If you are using NPM instead of Yarn, I think newer versions of NPM also support this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native-cheerio - npm
Start using react-native-cheerio in your project by running `npm i react-native-cheerio`. There are 10 other projects in the npm registry ...
Read more >
react-native-cheerio examples - CodeSandbox
Learn how to use react-native-cheerio by viewing and forking react-native-cheerio example apps on CodeSandbox.
Read more >
Cheerio tutorial - web scraping in JavaScript with ... - ZetCode
We can use filter to apply a filter on the elements. main.js. import fetch from 'node-fetch'; import { load } from 'cheerio'; const...
Read more >
cheerio
This video tutorial is a follow-up to Nettut's "How to Scrape Web Pages with Node.js and jQuery", using cheerio instead of JSDOM +...
Read more >
How to install cheerio in react-native? - Stack Overflow
I have been trying to use cheerio in React-native, but none of the solutions provided in https://github.com/cheeriojs/cheerio/issues/1058 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found