react-app-rewired icon indicating copy to clipboard operation
react-app-rewired copied to clipboard

Conflicting peer dependency: [email protected]

Open chackerian opened this issue 3 years ago • 2 comments

I'm getting this error when trying to use the package.

npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1" from [email protected]
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"3.4.3" from the root project
npm ERR!     peer react-scripts@">=2.1.3" from [email protected]
npm ERR!     node_modules/react-app-rewired
npm ERR!       dev react-app-rewired@"^2.1.6" from the root project

How can I properly install this? I have tried using --force and this doesn't work either.

chackerian avatar May 27 '22 22:05 chackerian

maybe npm i --legacy-peer-deps should works. This command will ignore the peer dependencies. By default, now npm is installing and validating peer deps

pedroSoaresll avatar May 30 '22 18:05 pedroSoaresll

A better way is to use the "overrides" property of package.json. See https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides

For example, I have "typescript": "^5.1.6" in devDependencies and then I have a top level package.json property

    "overrides": {
        "typescript": "$typescript"
    },

The dollar notation means it uses the exact value as specified in devDependencies - "overrides" only works if the version in "overrides" is exactly(!) the same as the one specified elsewhere. So having a version in "dependencies" or in "devDependencies", but then a "*" in "overrides" would be ignored, for example.

lll000111 avatar Aug 30 '23 09:08 lll000111