Invariant Violation: Browser history needs a DOM on `npm run build`
See original GitHub issueReact 16, Node 9.4.0, Mac OSX
I’m migrating from CRA to react-static.
I’ve setted up react-static-routes
and importing everything from react-static
instead of react-router-dom
for sure.
[BABEL] Note: The code generator has deoptimised the styling of "/Users/justfly/projects/taxi-static/dist/static.266c1799.js" as it exceeds the max of "500KB".
{ Invariant Violation: Browser history needs a DOM
at invariant (/Users/justfly/projects/taxi-static/node_modules/invariant/invariant.js:42:15)
at createBrowserHistory (/Users/justfly/projects/taxi-static/node_modules/history/createBrowserHistory.js:49:27)
at Object.defineProperty.value (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:4453:15)
at __webpack_require__ (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:30:30)
at Object.defineProperty.value (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:8741:16)
at __webpack_require__ (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:30:30)
at Object.<anonymous> (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:8496:16)
at __webpack_require__ (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:30:30)
at Object.defineProperty.value (/Users/justfly/projects/taxi-static/dist/static.266c1799.js:73:18)
at /Users/justfly/projects/taxi-static/dist/static.266c1799.js:11:17 name: 'Invariant Violation', framesToPop: 1 }
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top Results From Across the Web
react-router 4 - Browser history needs a DOM - Stack Overflow
However when I run the code I am getting Invariant Violation: Browser history needs a DOM in the browser. my server.js file code...
Read more >invariant violation browser history needs a dom react-router-dom
Server side rendeing using React Router: invariant violation browser history needs a dom react-router-dom : r/reactjs.
Read more >React Js: Invariant Failed: Browser History Needs A Dom
Invariant Violation : Browser history needs a DOM on npm run build #343 and importing everything from reactstatic instead of reactrouterdom for sure...
Read more >Tag: React Router - somewhat abstract
Error: Invariant failed: Browser history needs a DOM. Error: Invariant failed: Browser ... import {BrowserRouter, StaticRouter} from "react-router-dom";.
Read more >Server-side rendering with React Router "Browser history ...
Coding example for the question Server-side rendering with React Router "Browser history needs a DOM"-Reactjs.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I solved an issue.
The reason was that I had two instances of
Router
in my app - one for main app, and second for modal window. I could not use BrowserRoutes, cos both instances required the same history object created by createBrowserHistory, and in my case it was instantiated on server side, which leads to an error.Solution is simple refactor to history instantiation:
I want to know that too! I have the same issue and I don’t have any clue about in what file should I write this code.
EDIT
Solved this issue by removing the <BrowserRouter> tag from my App.jsx file.
Before:
After