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

Version 5.1.5 - multiple versions of @types/react causes typescript build errors #1320

Closed
captain-igloo opened this issue Feb 19, 2024 · 6 comments · Fixed by #1321 or #1322 · May be fixed by contentstack/contentstack-academy-playground#15 or contentstack/compass-starter-app#8
Assignees
Labels
bug Something isn't working

Comments

@captain-igloo
Copy link

captain-igloo commented Feb 19, 2024

From version 5.1.5 I get errors building my typescript project due to multiple versions of @types/react. I'm not sure if this is a problem with html-react-parser or with @types/react.

See 78b7a8e

Expected Behavior

Should build correctly, possibly should have dependency on @types/react version ^18.2.55 instead of 18.2.55

Actual Behavior

node_modules/@types/react/index.d.ts:4127:14 - error TS2300: Duplicate identifier 'ElementType'.

4127         type ElementType = string | React.JSXElementConstructor<any>;
                  ~~~~~~~~~~~

  node_modules/html-react-parser/node_modules/@types/react/index.d.ts:4127:14
    4127         type ElementType = string | React.JSXElementConstructor<any>;
                      ~~~~~~~~~~~
    'ElementType' was also declared here.

node_modules/@types/react/index.d.ts:4141:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

4141         type LibraryManagedAttributes<C, P> = C extends
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/html-react-parser/node_modules/@types/react/index.d.ts:4141:14
    4141         type LibraryManagedAttributes<C, P> = C extends
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

node_modules/html-react-parser/node_modules/@types/react/index.d.ts:4127:14 - error TS2300: Duplicate identifier 'ElementType'.

4127         type ElementType = string | React.JSXElementConstructor<any>;
                  ~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:4127:14
    4127         type ElementType = string | React.JSXElementConstructor<any>;
                      ~~~~~~~~~~~
    'ElementType' was also declared here.

node_modules/html-react-parser/node_modules/@types/react/index.d.ts:4141:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

4141         type LibraryManagedAttributes<C, P> = C extends
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react/index.d.ts:4141:14
    4141         type LibraryManagedAttributes<C, P> = C extends
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

Steps to Reproduce

git clone git@github.com:captain-igloo/html-react-parser-bug.git
cd html-react-parser-bug
npm ci
npm run build

Reproducible Demo

https://github.com/captain-igloo/html-react-parser-bug

Keywords

@types/react

@captain-igloo captain-igloo added the bug Something isn't working label Feb 19, 2024
@remarkablemark
Copy link
Owner

@captain-igloo thanks for the find! Would you like to open a PR for the fix? I think your suggestion to use ^18.2.55 sounds good

@remarkablemark
Copy link
Owner

PR for fix: #1321

@remarkablemark
Copy link
Owner

@captain-igloo
Copy link
Author

Thanks @remarkablemark , it works now.

@andrucz
Copy link

andrucz commented Feb 23, 2024

@remarkablemark why is @types/react a dependency rather than a dev dependency?

We have a few React apps that work as plugins of a legacy application that provides React 16 at runtime, so we can use 5.1.4 only.

@remarkablemark
Copy link
Owner

@andrucz the reason is because ESM types were not working when it was a devDependency. See #1314

I can make this a peerDependency if you think it's better for consumers to install their own version of @types/react

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment