sanitize-html: Community contribution required: Typescript Compilebreak after updating from nodejs 8 to 12

We used sanitize-html in a typescript project with node 8. After upgrading to node 12, the following typescript compilebreaks occurr in sanitize-html and its dependencies:

node_modules/@types/domutils/index.d.ts:6:10 - error TS2614: Module '"../../../../../node_modules/domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../../../../node_modules/domhandler/lib"' instead?

6 import { DomElement } from "domhandler";
           ~~~~~~~~~~

node_modules/@types/htmlparser2/index.d.ts:17:10 - error TS2614: Module '"../../../../../node_modules/domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../../../../node_modules/domhandler/lib"' instead?

17 export { DomElement, DomHandlerOptions, DomHandler, Element, Node } from 'domhandler';


node_modules/@types/sanitize-html/index.d.ts:17:10 - error TS2305: Module '"../../../../../node_modules/htmlparser2/lib"' has no exported member 'Options'.

17 import { Options } from "htmlparser2";

In the package.json, we are using

"sanitize-html": "^1.20.1",

and

"@types/sanitize-html": "^1.20.2",

for the typings.

Could anyone else update successfully to node 12?

Side-note - maybe it helps: It seems the dependency htmlparser2 was ported to typescript in https://github.com/fb55/htmlparser2/commit/759b1220c03e55a895f971deab9f1e94c30a7f61 which was released in https://github.com/fb55/htmlparser2/releases/tag/v4.0.0. Still sanitize-html pulls in "htmlparser2": "^3.10.0", as dependency.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 24 (9 by maintainers)

Most upvoted comments

This is still broken for me, post upgrade I see the following issues:

 ERROR  Failed to compile with 3 errors                                                                                                                                  5:18:41 PM

 error  in /test-project/node_modules/@types/domutils/index.d.ts

ERROR in /test-project/node_modules/@types/domutils/index.d.ts(6,10):
6:10 Module '"../../../../../../../test-project/node_modules/domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../../../../../../test-project/node_modules/domhandler/lib"' instead?
    4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
    5 |
  > 6 | import { DomElement } from "domhandler";
      |          ^
    7 | /***
    8 |  * Append an element after another
    9 |  *

 error  in /test-project/node_modules/@types/htmlparser2/index.d.ts

ERROR in /test-project/node_modules/@types/htmlparser2/index.d.ts(17,10):
17:10 Module '"../../../../../../../test-project/node_modules/domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../../../../../../test-project/node_modules/domhandler/lib"' instead?
    15 | import { DomHandler } from 'domhandler';
    16 | import * as DomUtils from 'domutils';
  > 17 | export { DomElement, DomHandlerOptions, DomHandler, Element, Node } from 'domhandler';
       |          ^
    18 |
    19 | export interface ParserOptions {
    20 |

 error  in /test-project/node_modules/@types/sanitize-html/index.d.ts

ERROR in /test-project/node_modules/@types/sanitize-html/index.d.ts(18,10):
18:10 Module '"../../../../../../../test-project/node_modules/htmlparser2/lib"' declares 'Options' locally, but it is not exported.
    16 | ///<reference types="htmlparser2"/>
    17 |
  > 18 | import { Options } from "htmlparser2";
       |          ^
    19 |
    20 | export = sanitize;
    21 |

 ERROR  Build failed with errors.

I’ve made a PR to @types/sanitize-html https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43870, which should resolve the issue with htmlparser2 types.

Still have the same issue on my end too.

I’ve opened an issue asking for some information as to what bc breaks, if any, come with htmlparser2 4.0.0.

On Fri, Dec 27, 2019 at 5:19 AM ceisele-r notifications@github.com wrote:

I just noticed that domhandler 3.0.0 is also typescript and therefore those types are used instead of @types/domhandler because domutils 2.0.0 pulls in domhandler ^3.0.0.

So since another dependency pulls in htmlparser2 4.0.0 that pulls in domutils ^2.0.0, domhandler ^3.0.0 is pulled in which overwrites the domutils 1.7.0 version pulled in parallel by sanitize-html.

So I think if sanitize-html would also upgrade the htmlparser2 dependency to ^4.0.0, the issue would be solved.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/sanitize-html/issues/320?email_source=notifications&email_token=AAAH27OEE6TUVCILQT723F3Q2XJCBA5CNFSM4J7ZNCY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHW6QTQ#issuecomment-569239630, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27JJZDAKAFFWR7KCOH3Q2XJCBANCNFSM4J7ZNCYQ .

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

PR is merged now 🎉

Whoops, somehow didn’t push master after publishing, fixed.

On Mon, Feb 24, 2020 at 5:49 PM David Mattia notifications@github.com wrote:

The upgrade doesn’t look like it enforces htmlparser2 4.x, the relevant line of code is:

https://github.com/apostrophecms/sanitize-html/blob/master/package.json#L30

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/sanitize-html/issues/320?email_source=notifications&email_token=AAAH27OJXKL7MGSOZQ47METRERFGRA5CNFSM4J7ZNCY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMZ2W5Q#issuecomment-590588790, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27OZ2O47KLFA3RLC23DRERFGRANCNFSM4J7ZNCYQ .

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his