Uncaught SyntaxError: The requested module ‘/node_modules/.vite/react-router……Switch

I used vite to create a react project and reported an error when doing nested routing

The error prompt is the following code:

import { BrowserRouter, Route, Switch } from 'react-router-dom';

There is an error in the switch.

The NPM package version of the project at that time is as follows:

{
……
  "dependencies": {
    "react": "^17.0.0",
    "react-dom": "^17.0.0",
    "react-router": "^6.0.2",
    "react-router-dom": "^6.0.2"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^1.0.0",
    "vite": "^2.6.4"
  }
}

There is a switch method in the react route DOM, but the version may be too high and vite does not fit, so I choose to reduce the react route DOM to V5 version:

npm i [email protected]

Restart the project and the error will be solved~

 

Similar Posts: