score:0

in my case, i got the error indicate that 'librarymanagedattributes' is declared in 2 different locations. follow the paths, i realized that an installed module also has a package.json file which also add "@types/react" as dep, and its version is not the same as the one in the root package.json file. i changed these two to the same version and the problem was solved.

score:0

i had a conflicting version request for react in another module i used. fixing that and re-installing with yarn didn't help me either.

using npm instead of yarn however solved it for me.

hope this helps someone.

score:0

what worked for me was deleting react and @types/react from package.json, then in zsh:

rm -rf node_modules/**/react
npm i react @types/react

score:0

for me, it caused by only referenced @types/react-redux. fixed by npm i --save-dev @types/react, and so the package.json looks like this:

  ...
  "devdependencies": {
    "@types/react": "^16.9.19",
    "@types/react-redux": "^7.1.7"
    ...
  }

score:0

i had this issue while working with linked dependencies. my linked package lives in a lerna repo, and it had @types/react as a devdependency. i added @types/react as a peerdependency, switched my workflow to yalc, and was able to continue.

score:1

c:/users/japa/source/repos/reacttestapp/templateexample/clientapp/node_modules/@types/react/index.d.ts
typescript error in c:/users/japa/source/repos/reacttestapp/templateexample/clientapp/node_modules/@types/react/index.d.ts(2835,14):
duplicate identifier 'librarymanagedattributes'.  ts2300

in my case i needed to solve the problem manually (using principle described in ts2300). the problem arose once i added reactkendo to my project.

  1. went to clientapp directory in my project clientapp\node_modules\@types
  2. backed up the react directory and then deleted it
  3. clean + build + run project and no more above error occures
  4. i recovered the react folder after the bug disappeared and error seems to be gone forever, so it seems to me like typical magic bug somewhere in the universe :-)

i did not need to change anything else in config files.

score:2

i have the same issue after yarn upgrade @types/react-router-dom. git diff shows multiple versions of @types/react resolved. in my case, yarn upgrade @types/react resolves the issue. removing yarn.lock should help.

it seems a fresh (without yarn.lock) install would resolve packages to a consistent state, but a partial upgrade would not resolve the dependencies globally. thus manual tweaks may be necessary to upgrade all involved packages.

score:3

related to the question, running npm list @types/react from the directory of your package.json should list duplicate type definitions found in your project.

score:3

using yarn-deduplicate fixed the issue for me.

steps:

  1. optional install yarn-deduplicate package or use npx in step two
npm install -g yarn-deduplicate

or

yarn global add yarn-deduplicate
  1. run yarn-deduplicate
yarn-deduplicate yarn.lock --packages @types/react yarn.lock

or

npx yarn-deduplicate --packages @types/react yarn.lock
  1. remove node_modules folder
rm -rf node_modules
  1. reinstall dependencies
yarn install

score:4

in our case, we fixed it by

  1. moving all @types/* packages to devdependencies

  2. rm -rf yarn.lock and rm -rf node_modules

  3. run yarn install again

score:5

in my case the error showed up when the version numbers of @types/react (v17.0.3) and @types/react-dom (v17.0.2) have not been in sync.

to solve the issue, i removed @types/react because it gets hoisted from @types/react-dom. you can verify that by executing yarn why @types/react.

score:7

the easiest way to fix this for me was to delete my node_modules directory and yarn.lock/package-lock files and then do a yarn install to reinstall all the node modules.

score:20

for me i had react types duplicated in react-redux, react, and react-intl when i upgraded react-intl. the least intrusive fix that's worked for me so far is to run this:

npx yarn-deduplicate --packages @types/react yarn.lock

if the resulting diff of the lockfile looks correct, go ahead and delete node_modules, then yarn to get fresh packages off the deduplicated lockfile.

score:24

i got the same error. i managed to fixed it by removing my '@types/react' and then installing them again.

yarn remove @types/react
yarn add --dev @types/react

score:44

this seems to be a typescript issue.

my current workaround is adding "skiplibcheck": true to tsconfig.json.

i want to stress that that is only a workaround and not a fix to the problem it self.

score:152

this seems te happen because yarn resolves multiple versions of a package; @types/react in this particular case. yarn resolves @types/react from your package.json and as a dependency of @types/react-dom.

take the following snippet from my package.json:

"devdependencies": {
  "@types/react": "^15.0.16",
  "@types/react-dom": "^0.14.23"
  ...
}

the yarn.lock that is created after you run yarn install contains something similar to this:

"@types/react-dom@^0.14.23":
  version "0.14.23"
  resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-0.14.23.tgz#cecfcfad754b4c2765fe5d29b81b301889ad6c2e"
  dependencies:
    "@types/react" "*"

"@types/react@*":
  version "16.4.14"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-16.4.14.tgz#47c604c8e46ed674bbdf4aabf82b34b9041c6a04"
  dependencies:
    "@types/prop-types" "*"
    csstype "^2.2.0"

"@types/react@^15.0.16":
  version "15.6.19"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-15.6.19.tgz#a5de18afe65b0f29767328836b48c498a5d3a91b"

notice that @types/react-dom depends on any version of @types/react as indicated by "*". yarn resolves two versions of @types/react: "16.4.14" and "15.6.19". this results in the type conflicts you mentioned.

the solution is to add a resolutions field to your package.json to tell yarn to resolve a specific version of @types/react. take the following sample:

"resolutions": {
  "@types/react": "^15.0.16"
}

run yarn install again. notice the change in the yarn.lock file:

"@types/react-dom@^0.14.23":
  version "0.14.23"
  resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-0.14.23.tgz#cecfcfad754b4c2765fe5d29b81b301889ad6c2e"
  dependencies:
    "@types/react" "*"

"@types/react@*", "@types/react@^15.0.16":
  version "15.6.19"
  resolved "https://registry.yarnpkg.com/@types/react/-/react-15.6.19.tgz#a5de18afe65b0f29767328836b48c498a5d3a91b"

yarn now resolves the same version "15.6.19" for both "@types/react@*" and "@types/react@^15.0.16" dependencies.

i would like to know myself why this is needed. i would expect yarn to understand it can resolve dependency "@types/react" "*" with "@types/react@^15.0.16" instead of resolving it with the latest version of @types/react.


Related Query

More Query from same tag