remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.12k stars 10.31k forks source link

'react-router-dom' does not contain a default export (imported as 'BrowserRouter'). #7454

Closed danidanimoraes closed 4 years ago

danidanimoraes commented 4 years ago

Hey. I am trying to do my first react app and everything is working fine, until I tried to use react-router-dom.

I've just imported: import BrowserRouter from 'react-router-dom';

and wrapped my existing functioning app with . As soon as I use the BrowserRouter tag, the app gets this error:

./src/App.js Attempted import error: 'react-router-dom' does not contain a default export (imported as 'BrowserRouter').

I saw a lot of similar bugs, but most of them have problems when importing from react-router instead of react-router-dom, and other problems were solved after deleting node_modules and restarting the server, but this didn't work for me.

I've tried other react-router-dom versions, but I had the same problem. Here are the versions I tried: 5.2.0, 5.1.0, 5.0.0.

If I open BrowserRouter.js, it has "export default BrowserRouter;", so I don't know what is happening.

Am I missing something os this is really a bug?

timdorr commented 4 years ago

It doesn't have a default export: https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/index.js

You need to use a named import: import { BrowserRouter } from 'react-router-dom'

danidanimoraes commented 4 years ago

Thank you, I can't believe it was so simple. Sorry for the inconvenience.

SaiChinnu17 commented 3 years ago

Hai I get error my 1st React App

./src/index.js Attempted import error: 'react-router-dom' does not contain a default export (imported as 'ReactRouterDom)' how solve this error

SaiChinnu17 commented 3 years ago

Hai how to solva this error

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

shaikabdulkhadar1 commented 3 years ago

Hi. I started learning React recently. I am getting this error "Attempted import error: 'react-router-dom' does not contain a default export (imported as 'Link')." This is how I am importing it import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';

I don't know how to fix it. Can anyone help.

Ramin-Khodaie commented 3 years ago

I am trying import {WithRouter} from react-router, but I faced with this : 'withRouter' is not exported from 'react-router'. I follow what is in react-router documentation. is there anyone to help?