sanitize-html icon indicating copy to clipboard operation
sanitize-html copied to clipboard

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

Open ceisele-r opened this issue 6 years ago • 24 comments

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.

ceisele-r avatar Dec 27 '19 09:12 ceisele-r

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.

ceisele-r avatar Dec 27 '19 10:12 ceisele-r

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 [email protected] 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

boutell avatar Jan 02 '20 13:01 boutell

I did upgrade to htmlparser2 4.x, and it works great and all tests pass etc., but one user has reported a similar issue since the upgrade. I need a simple procedure to reproduce this issue. Ideally a failing test case PR.

boutell avatar Feb 24 '20 14:02 boutell

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

dmattia avatar Feb 24 '20 22:02 dmattia

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

On Mon, Feb 24, 2020 at 5:49 PM David Mattia [email protected] 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

boutell avatar Feb 24 '20 23:02 boutell

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.

JamesMcMahon avatar Mar 19 '20 22:03 JamesMcMahon

Still have the same issue on my end too.

InputNeuron avatar Mar 23 '20 17:03 InputNeuron

This is also broken for us (https://github.com/matrix-org/matrix-appservice-irc/issues/1003)

Half-Shot avatar Mar 30 '20 13:03 Half-Shot

Same here, have to use custom / very simplified typings for now.

vladimiry avatar Mar 30 '20 13:03 vladimiry

Same for me.

kieusonlam avatar Apr 01 '20 03:04 kieusonlam

We do not use typescript in house, so this will need to be resolved by a community contributor who is familiar with it. We are waiting for a PR, in other words. Thank you for verifying the issue — but past this point please do not add "me too" comments until there is some indication that an attempt has been made to resolve the issue.

boutell avatar Apr 01 '20 12:04 boutell

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

dsyncerek avatar Apr 13 '20 20:04 dsyncerek

That's great! Since we don't use TypeScript in-house, would someone please check out the PR from @dsyncerek and confirm that it does in fact solve the problem for them as well? cc @kieusonlam @vladimiry @Half-Shot @burtonator

boutell avatar Apr 14 '20 12:04 boutell

Actually it sounds like there might not be anything to do on our end?

boutell avatar Apr 14 '20 12:04 boutell

yes, only @types/sanitize-html needs adjustments, as the htmlparser2 v4 has been rewritten to TypeScript, so it uses own typings instead of community @types/htmlparser2.

dsyncerek avatar Apr 14 '20 12:04 dsyncerek

Until @dsyncerek DefinitelyTyped PR is merged I have solved the issues by fixing my project's dependencies to these versions:

{
    ...
    "sanitize-html": "1.21.0",
    "@types/sanitize-html": "1.20.2",
    "@types/node": "10.17.21"   //12.12.6 for node 12
    ...
}

Note: @types/node was required in my case as htmlparser2 seems to have issues with this sanitize-html version in conjunction with my node version - you might be able to skip it

rico-ocepek avatar Apr 22 '20 11:04 rico-ocepek

PR is merged now 🎉

dsyncerek avatar Apr 26 '20 17:04 dsyncerek

Thanks @dsyncerek , I can confirm its working not in 1.23.0 with types in 1.23.0.

ceisele-r avatar Apr 27 '20 05:04 ceisele-r

👍

On Mon, Apr 27, 2020 at 1:53 AM ceisele-r [email protected] wrote:

Closed #320 https://github.com/apostrophecms/sanitize-html/issues/320.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/sanitize-html/issues/320#event-3274084821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27J75ARQHQBBNWXFOODROUMWVANCNFSM4J7ZNCYQ .

--

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

boutell avatar Apr 27 '20 17:04 boutell

Good Afternoon: I tried everything on this thread still having this problem:

node -v v15.0.1

"dependencies": { "@apollo/react-hooks": "^3.1.3", "apollo-cache-inmemory": "^1.6.5", "apollo-client": "^2.6.8", "apollo-link": "^1.2.14", "apollo-link-context": "^1.0.20", "apollo-link-http": "^1.5.16", "classnames": "^2.2.6", "graphql": "^14.6.0", "graphql-tag": "^2.10.3", "jsonwebtoken": "^8.5.1", "lodash-es": "^4.17.15", "mid-common": "workspace:", "react": "^16.12.0", "react-apollo": "^3.1.3", "react-dom": "^16.12.0", "react-router": "^5.1.2", "react-router-dom": "^5.1.2", "sanitize-html": "^2.0.0", "semantic-ui-react": "^2.0.0" }, "devDependencies": { "@types/classnames": "2.2.10", "@types/eslint": "6.1.8", "@types/jest": "^26.0.15", "@types/jsonwebtoken": "8.3.9", "@types/lodash-es": "4.17.3", "@types/react": "^16.9.19", "@types/react-dom": "^16.9.7", "@types/react-router": "5.1.4", "@types/react-router-dom": "5.1.3", "@types/sanitize-html": "1.27.0", "apollo": "^2.22.0", "current-git-branch": "^1.1.0", "eslint": "^6.8.0", "jest": "^26.6.1", "minimatch": "^3.0.4", "ts-jest": "^23.10.5" }, "jest": { "transform": { "^.+\.tsx?$": "ts-jest" }, "testRegex": "(/tests/.|(\.|/)(test|spec))\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } }

ERROR:

TS2614: Module '"../../../../../../../Desktop/workflow-ui/node_modules/domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../../../../../../Users/a-zhaque/Desktop/workflow-ui/node_modules/domhandler/lib"' instead?

zhaque44 avatar Nov 07 '20 19:11 zhaque44