question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use AdminJS + Typescript + (@types/)React v17

See original GitHub issue

AdminJS relies on react v16. If the rest of your app uses React v17, Typescipt gets very mad.

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

3094         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  ../node_modules/adminjs/node_modules/@types/react/index.d.ts:3091:14
    3091         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.

../node_modules/@types/react/index.d.ts:3105:13 - error TS2717: Subsequent property declarations must have the same type.  Property 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.

3105             a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
                 ~

  ../node_modules/adminjs/node_modules/@types/react/index.d.ts:3104:13
    3104             a: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
                     ~
    'a' was also declared here.

This comes from different versions of @types/react being installed:

$ cat node_modules/adminjs/node_modules/@types/react/package.json | grep version
    "version": "16.14.17",
$ cat node_modules/@types/react/package.json | grep version
    "version": "17.0.30",

You can see the miss-matched versions of react with npm ls react and that react-redux is the culprit:

β”œβ”€β”¬ @testing-library/react@12.1.1
β”‚ └── react@17.0.2 deduped
β”œβ”€β”¬ adminjs@5.2.2
β”‚ β”œβ”€β”¬ @adminjs/design-system@2.0.2
β”‚ β”‚ β”œβ”€β”¬ @carbon/icons-react@10.41.0
β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ β”œβ”€β”¬ react-datepicker@3.8.0
β”‚ β”‚ β”‚ β”œβ”€β”¬ react-onclickoutside@6.12.0
β”‚ β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ β”‚ β”œβ”€β”¬ react-popper@1.3.11
β”‚ β”‚ β”‚ β”‚ β”œβ”€β”¬ @hypnosphi/create-react-context@0.3.1
β”‚ β”‚ β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ └── react@16.13.1 deduped
β”‚ β”œβ”€β”¬ react-beautiful-dnd@13.1.0
β”‚ β”‚ β”œβ”€β”¬ react-redux@7.2.5
β”‚ β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”‚ β”œβ”€β”€ react@17.0.2 deduped
β”‚ β”‚ └─┬ use-memo-one@1.1.2
β”‚ β”‚   └── react@17.0.2 deduped
β”‚ β”œβ”€β”¬ react-dom@16.13.1
β”‚ β”‚ └── react@16.13.1 deduped
β”‚ β”œβ”€β”¬ react-i18next@11.12.0
β”‚ β”‚ └── react@17.0.2 deduped
β”‚ β”œβ”€β”¬ react-redux@7.2.0
β”‚ β”‚ └── react@16.13.1 deduped. // <---
β”‚ β”œβ”€β”¬ react-router-dom@5.2.0

Installed libraries and their versions

"adminjs": "5.2.2",
"@adminjs/passwords": "2.0.0",
"@adminjs/sequelize": "2.0.0",
"react": "17.0.2",
"@types/react": "17.0.30",

Desktop (please complete the following information if relevant):

  • OSX
  • node version - v15.14.0
  • npm version - 7.20.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vladiulianbogdancommented, Nov 24, 2021

I have the same problem. In my project, the only module that is using React is AdminJS. I’ve tried to see why there were 2 different versions of React in my project and it seems that, if I understand correctly, admin js is bringing them:

yarn why node_modules/@types/react/

yarn why v1.22.4
[1/4] πŸ€”  Why do we have the module "node_modules/@types/react/"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] πŸ”  Finding dependency...
[4/4] 🚑  Calculating file sizes...
=> Found "@types/react@17.0.36"
info Has been hoisted to "@types/react"
info Reasons this module exists
   - Hoisted from "adminjs#react-beautiful-dnd#react-redux#@types#react-redux#@types#react"
   - Hoisted from "adminjs#react-beautiful-dnd#react-redux#@types#react-redux#@types#hoist-non-react-statics#@types#react"
info Disk size without dependencies: "196KB"
info Disk size with unique dependencies: "1.35MB"
info Disk size with transitive dependencies: "1.35MB"
info Number of shared dependencies: 3
=> Found "adminjs#@types/react@16.14.4"
info This module exists because "adminjs" depends on it.
info Disk size without dependencies: "168KB"
info Disk size with unique dependencies: "1.3MB"
info Disk size with transitive dependencies: "1.3MB"
info Number of shared dependencies: 2
✨  Done in 1.29s.

Is there a fix or a way to work around this issue?

1reaction
evantahlercommented, Oct 20, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

@types/react - npm
Start using @types/react in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
Next.js is not recognizing '@types/react' - Stack Overflow
js app with npm run dev I get an error message saying that I don't have the required packages to run Next with...
Read more >
SVG Typescript error - Developers Community by KeenThemes
'SVG' cannot be used as a JSX component. Its instance type 'InlineSVG' is not a valid JSX element. The types returned by 'render()'...
Read more >
Node js admin panel with mysql github
I hope this really help others who wish to use Ms SQL while using node. ... No need to register - simply download...
Read more >
Module not found: Can't resolve 'react-dom' error | bobbyhadz
with NPM npm install react-dom react # πŸ‘‡οΈ ONLY If you use TypeScript npm install --save-dev @types/react-dom @types/react ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found