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

Created on 26 Jun 2020  路  2Comments  路  Source: ReactTraining/react-router

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?

Most helpful comment

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'

All 2 comments

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'

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewpillar picture andrewpillar  路  3Comments

ArthurRougier picture ArthurRougier  路  3Comments

Radivarig picture Radivarig  路  3Comments

hgezim picture hgezim  路  3Comments

davetgreen picture davetgreen  路  3Comments