-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Cheerio breaks when bundling with Rollup #1689
Comments
Hmm, yes this require in function .load() needs fully built Cheerio object. It uses basically node module caching ability and this is why require are inside that function and not top level. |
I managed to use provided cheerio rollup test, but If I test that generated file it fails. So I have no idea, is my modified cheerio build failing or is rollup configuration flawed. My build does work with all Jest tests so I think configuration, but I am not used rollup before so I am not sure. |
Yes, I made this test to show that the bundling doesn't work. If we could remove the circular dependency the test would not fail. The project would need to be restructured slightly, because Rollup cannot rely on the node module caching ability. This would also be a problem when rewriting Cheerio using ESM, as there (ideally) can be no dynamic So the question is how to restructure so there are no circular dependencies. |
I modified const cheerio = require('cheerio');
const $ = cheerio.load('<html></html>')
console.log($.html()); and it worked |
Superb work on this one. I've included cheerio as a dependency using |
Due to a circular dependency Rollup emits warnings when bundling Cheerio, and the resulting code is also broken. This wasn't possible in
1.0.0-rc.3
either, but there the problem was inreadable-stream
andhtmlparser2
, which could then be included as external dependencies. In1.0.0-rc.5
the problem is in Cheerio.This is caused by
require('./cheerio');
in lib/static.js#L31Somehow this causes
static.js
to be included afterattributes.js
, which relies onstatic.js
when doingvar text = require('../static.js').text
in lib/api/attributes.js#L8.Ideally this would be solved by refactoring Cheerio in ESM, but just removing the circular dependency in
static.js
would also work.I made a repro here: hansottowirtz/cheerio-bundling-repro.
The text was updated successfully, but these errors were encountered: