Giter Club home page Giter Club logo

Comments (4)

davideicardi avatar davideicardi commented on May 23, 2024 1

I have done some investigations. From my test the problem is inside htmlparser2 module, only in version 3.10.1, the version used by cheerio.
It contains the following code: require("entities/maps/entities.json").
But the correct path is require("entities/lib/maps/entities.json"); (with lib).

Here a simple test.

  • create a new node project
  • install entities: npm i entities
  • create a new index.js file with: require("entities/maps/entities.json")
  • run it

I get an error module not found. Like with live-plugin-manager.

If you look at the latest version of htmlparser2, https://github.com/fb55/htmlparser2/blob/master/src/Tokenizer.ts, the code is now correct.

A quick workaround, until cheerio is update htmlparser2 version, is to just install the latest version (4.0.0) of htmlparser2 after cheerio.

Here an unit test:

		it("issue 14: installing cheerio", async function() {
			await manager.installFromNpm("cheerio", "1.0.0-rc.3");
			await manager.installFromNpm("htmlparser2", "4.0.0");

			const cheerio = manager.require("cheerio");
			assert.isDefined(cheerio, "Plugin is not loaded");

			// try to use the plugin
			const $ = cheerio.load('<h2 class="title">Hello world</h2>')

			$('h2.title').text('Hello there!')
			$('h2').addClass('welcome')
			
			assert.equal($.html(), '<html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>');
		});

See also: cheeriojs/cheerio#1339 (comment)

from live-plugin-manager.

davideicardi avatar davideicardi commented on May 23, 2024

I think that you are right. The bug is related probably to the fact that the main file is inside a subdirectory, lib. Strange that I never see this problem in other modules... seems to be quite common.

Regarding the fix I'm now sure. I need some more time to investigate ...

If you are able to publish a pull request I appreciate. Probably we need to try to reproduce it in one of the unit test, it should be quite easy I hope.

Thank you for the bug report

from live-plugin-manager.

cubehouse avatar cubehouse commented on May 23, 2024

Sorry for the delay, I've added a pull request with my fix. I don't think it's particularly robust though, but it does fix requiring Cheerio from within the VM.

from live-plugin-manager.

davideicardi avatar davideicardi commented on May 23, 2024

Let me know if you are able to use the proposed workaround (install version 4 of htmlparser2)

from live-plugin-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.