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

error while running with webpack bundle in nodejs #439

Closed
mohit-singh-pepper opened this issue Jun 28, 2023 · 7 comments
Closed

error while running with webpack bundle in nodejs #439

mohit-singh-pepper opened this issue Jun 28, 2023 · 7 comments

Comments

@mohit-singh-pepper
Copy link

mohit-singh-pepper commented Jun 28, 2023

Getting following error while trying to run turndown. I am using esbuild to get the bundle for same.

/Users/mohitsingh/Documents/abc/dom-text-abc-function/dist/main.js:21918
        } else if (stack.top instanceof impl.HTMLTemplateElement) {
                             ^

TypeError: Right-hand side of 'instanceof' is not an object
    at insertElement (/Users/mohitsingh/Documents/abc/dom-text-scrapper-agc/dist/main.js:21918:30)
    at insertHTMLElement (/Users/mohitsingh/Documents/abc/dom-text-agc-function/dist/main.js:21906:19)
    at before_head_mode (/Users/mohitsingh/Documents/abc/dom-text-agc-function/dist/main.js:24842:27)
    at before_head_mode (/Users/mohitsingh/Documents/abc/dom-text-abc-function/dist/main.js:24859:9)
    at before_html_mode (/Users/mohitsingh/Documents/abc/dom-text-abc-function/dist/main.js:24822:9)
    at initial_mode (/Users/mohitsingh/Documents/abc/dom-text-abc-function/dist/main.js:24783:9)
@mohit-singh-pepper
Copy link
Author

Its due to this fgnass/domino#146

@mohit-singh-pepper
Copy link
Author

Is there a workaround, anyone know of ?

@martincizek
Copy link
Collaborator

Not familiar with webpack, so the workaround in general terms:

  1. use the browser build as the dependency - the browser build does not contain domino (see package.js)
  2. if your build is for a browser, you're done. If it is for an environment without DOM parser, you need to bring your own DOM parser (e.g. jsdom) and call turndown with a DOM object instead of string.

For reference, discussion about separating turndown and the DOM implementation: #265 .

@castroCrea
Copy link

@mohit-singh-pepper did you found a solution ?

julienc91 added a commit to julienc91/caviardeul that referenced this issue Oct 15, 2023
The domino library looks abandoned and had compatibility issues with the latest nextjs versions. Luckily, turndownjs accepts a JSDOM document as input and not only raw text.

Workaround for:
* mixmark-io/turndown#439 (occurred after upgrading nextjs from 13.4 to 13.5)
* mixmark-io/turndown#378 (occurred after upgrading nextjs from 12.X to 13.X)
@baltagih2
Copy link

For anyone still running into this problem, the following worked for me (based on the commit from @julienc91 above):

npm i jsdom
npm i --save-dev @types/jsdom

import { JSDOM } from "jsdom";
import TurndownService from "turndown";

const turndownService = new TurndownService();


const result = turndownService.turndown(
      JSDOM.fragment(your_html_content)
    );

@pavelhoral
Copy link
Collaborator

I think this issue should be solved with the latest Turndown release 7.2.0. Can you confirm @mohit-singh-pepper ?

@pavelhoral
Copy link
Collaborator

This should be solved with the introduction of custom domino fork in the latest release #461.

enricoros added a commit to enricoros/big-AGI that referenced this issue Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants