Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TypeError: cheerio is not a function] with babel-node and Typescript ES6 mode when using cheerio(html) #6535

@tomduncalf

Description

@tomduncalf

I'm new to the Typescript world so might be misunderstanding how this should work, but from what I can see in #5688, cheerio should work with ES6 mode in Typescript. However, it seems that you cannot just call cheerio(html) - tsc will compile it fine, but babel-node spits out an error TypeError: cheerio is not a function. You instead have to call cheerio.load(html) and then interact with that (via .root() to get the CheerioElement).

Like I say, new to this so I may be making a rookie error here! I've uploaded a simple test case demonstrating what I mean: https://github.com/tomduncalf/cheerio-testcase

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions