I am trying to create an app, I just started with React, I have created the project with Vite and I am trying to import router-react but something is wrong. I'm using "npm run dev" to test react on localhost (see scripts further down in package.json if needed). It's funny because it looks like you're looking for the resource inside the vite module folder (/node_modules/.vite/....) and not directly inside node_modules to find "/node_modules/react-router-dom".
The error is the following:
Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/react-router-dom.js?v=dc8c6822' does not provide an export named 'Switch' (at App.jsx:4:3)
My App.jsx where the error occurs:
import { Navbar } from "./components/navbar/Navbar";
import {
BrowserRouter,
Switch,
Route,
Link
} from "react-router-dom";
const App = () => {
return <Navbar/>
}
export default App
I know it's very sloppy and I don't think it matters much, but just in case it could be of any help, I'll show you my current folder structure:
My vite.config.js is the default, I haven't touched anything so far:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
My package.json is the following. The line "type":"module" came by default with Vite and I have tried removing it and leaving it but the result is the same.
{
"name": "wallet-monitor",
"private": true,
"version": "0.0.0",
"type": "module",
"description": "Una APP para gestionar tus finanzas personales",
"main": "backend/index.js",
"scripts": {
"watch": "nodemon backend/index",
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2"
},
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"vite": "^3.1.0"
}
}
What have I done wrong? What do I need to implement? This is caused by Vite? I have searched for info about the error but I don't fully understand and I don't know what to do. Thank you!