Search code examples
react-router-domwebstorm

Cannot resolve symbol 'Routes' in react-router-dom v6 using WebStorm IDE


I've just installed react-router-dom v6 in WebStorm IDE and my problem is that in some of my files I can't import Routes properly

enter image description here

The problem seems to be that it's choosing between one of these two files:

enter image description here enter image description here

The @types react-router-dom 5.3.3 seems to be the problem. In my main app.tsx file it's working but in any .js files it's not working.


Solution

  • Delete the @types/react-router-dom directory in your node_modules. Those types are for the previous version of react-router. v6 is written in TypeScript, so these superfluous and older types are misleading the IDEA. Make sure those types aren't in your package.json, as well. You'll be prompted to rebuild your package.json / node_modules folder at this point.