Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse5.parseFragment is not a function => parsers/parse5.js|ts #1847

Closed
MathiasBoisgardDev opened this issue May 7, 2021 · 4 comments · Fixed by #1873 · 4 remaining pull requests
Closed

parse5.parseFragment is not a function => parsers/parse5.js|ts #1847

MathiasBoisgardDev opened this issue May 7, 2021 · 4 comments · Fixed by #1873 · 4 remaining pull requests

Comments

@MathiasBoisgardDev
Copy link

MathiasBoisgardDev commented May 7, 2021

Hello !

I found an issue after searching for a while where it came from.

I use enzyme in a project for my Unit Tests, and the library uses cheerio for its internal function 'render'

The problem

When I execute my tests, every call to 'render' method from enzyme has an error :

TypeError: parse5.parseFragment is not a function

This error only occurs for cheerio version >v1.0.0-rc.5 as the structure of your library changed between .5 and .6
Before the import of parse5 was made directly in lib/parse.js and then moved to parsers/parse5.js

The problem is that when you require('parse5') in parsers/parse5.js, you actually require the file itself, so

var parse5 = require('parse5');
is actually an object containing the function parse and render and not the functions from the library parse5 (parse, parseFragment and serialize)

The solution

I can do a Pull request to change the name of the file and so avoid this problem (tested locally and functionnal)

@fb55
Copy link
Member

fb55 commented May 7, 2021

Hi @MathiasBoisgardDev, thanks for the report! Could you provide some details on which environment you are using? Module resolution as it is done within Node shouldn't have an issue here.

@MathiasBoisgardDev
Copy link
Author

Yeah sure:

MacOS Big Sur : v11.3.1
node : v12.14.1

Do you need more than those information ?

@egor-yolabs
Copy link

egor-yolabs commented May 7, 2021

Just wanted to note that I have the same exact issue with this library. I have to lock it down to rc5 to get around it. I'm on latest Windows, latest stable node.js.

@MathiasBoisgardDev
Copy link
Author

Same, everything works fine by locking on .5
Would be great to be able to be up to date though

fb55 added a commit that referenced this issue May 17, 2021
fb55 added a commit that referenced this issue May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment