timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.76k stars 425 forks source link

Conflicting peer dependency: typescript@3.9.10 #626

Open chackerian opened 2 years ago

chackerian commented 2 years ago

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

npm ERR! Conflicting peer dependency: typescript@3.9.10
npm ERR! node_modules/typescript
npm ERR!   peerOptional typescript@"^3.2.1" from react-scripts@3.4.3
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 react-app-rewired@2.1.8
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.

pedroSoaresll commented 2 years ago

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

lll000111 commented 10 months ago

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.