React require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")
Import creatBrowserHistory
with curly brackets. It's exported as a named export.
// history.js
import { createBrowserHistory } from "history";
export default createBrowserHistory();
Then import and use it in index.
// index.js
import history from "./history";
import { Provider } from "react-redux";
import store from "./store/store";
const AppContainer = () => (
<Router history={history}>
<Provider store={store}>
<Route path="/" component={App} />
</Provider>
</Router>
);
I've changed this
import createHistory from 'history/createBrowserHistory'
to this
import { createBrowserHistory } from 'history'
In my code, this error occurs when running a unit test. An enzyme or jest is possible by interpreting the ES6 code differently. Make in the package history export default.
My import code now
import { createBrowserHistory } from 'history'
Here is the full history.js
code
import { createBrowserHistory } from 'history';
export default createBrowserHistory();