I have read through a ton of posts on this and cannot find a solution. I built the app with Create-React-App so I didn't have to think about Babel/WebPack. I recently upgraded my dependencies and ran into this issue. The error is fairly lengthy, but here is the first part of bundle.js error...
Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: .../src/StudentDashboard/ClientApp/node_modules/history/index.js: Cannot read properties of undefined (reading 'originalPositionFor')
The app is React on the fron end and .Net Core on the back end. I start the SPA from startup.cs with...
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
I have tried:
- running babel-upgrade with npx
- Adding babel.config.json with
"presets": ["@babel/preset-env", "@babel/preset-react"]
- Adding dev dependencies of
"@babel/core": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"babel-loader": "^8.2.3",
None of the above fixed the error. I even closed and restarted VS Code just in case. Any thoughts on how to fix would be appreciated.
I have read through a ton of posts on this and cannot find a solution. I built the app with Create-React-App so I didn't have to think about Babel/WebPack. I recently upgraded my dependencies and ran into this issue. The error is fairly lengthy, but here is the first part of bundle.js error...
Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: .../src/StudentDashboard/ClientApp/node_modules/history/index.js: Cannot read properties of undefined (reading 'originalPositionFor')
The app is React on the fron end and .Net Core on the back end. I start the SPA from startup.cs with...
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
I have tried:
- running babel-upgrade with npx
- Adding babel.config.json with
"presets": ["@babel/preset-env", "@babel/preset-react"]
- Adding dev dependencies of
"@babel/core": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"babel-loader": "^8.2.3",
None of the above fixed the error. I even closed and restarted VS Code just in case. Any thoughts on how to fix would be appreciated.
Share Improve this question edited Feb 3, 2022 at 16:35 Clay Hess asked Feb 3, 2022 at 16:22 Clay HessClay Hess 2581 gold badge8 silver badges27 bronze badges 5-
are you using
[email protected]
with[email protected]
? Because they are not patible and you should stay on[email protected]
– dbuchet Commented Feb 3, 2022 at 16:30 - Here are the React entries from my package.json... "react": "^17.0.2", "react-dom": "^17.0.2", "react-router-bootstrap": "^0.26.0", "react-router-dom": "^6.2.1", "react-scripts": "^5.0.0", "reactstrap": "^9.0.1", I do not have history@. Should I? – Clay Hess Commented Feb 3, 2022 at 16:34
- I bed through my lock file and found that react-router (6.2.1) has a dependency of History: ^5.2.0 – Clay Hess Commented Feb 3, 2022 at 16:40
- Looks like you could have your solution here: stackoverflow./questions/70965180/… – dbuchet Commented Feb 3, 2022 at 16:44
- I went through the link you shared and it did not fix my issue. Even though the post says a fix was made, I downgraded to core 7.16.12 and router-dom 5.2.0. Did not help. Any other thoughts? – Clay Hess Commented Feb 3, 2022 at 17:26
4 Answers
Reset to default 1I figured out the issue I was facing. While the error displayed pointed me towards Babel, which is what I thought, the real issue was related to changes to React routing.
I had to wrap all my <route>
elements in a <Routes>
tag. I then had to change the ponent attribute to element and place the ponent in html-like syntax...from {Home}
to {<Home/>}
.
One other change was that my import was pulling from react-router. I changed it to react-router-dom.
This was all in my App.js.
Here are a couple of links that might be helpful to others who, like me, did not realize there was a change.
https://dev.to/gabrlcj/react-router-v6-some-of-the-new-changes-181m
https://www.c-sharpcorner./article/react-router-v6-what-changed-and-upgrading-guide/
This error es when you install the latest version of npm like this npm install react-router-dom@6 after running npm start it will fail to pile because of @babel/core is inpatible with the npm version so you have to revert back to babel previous versions run this:
npm i -D @babel/[email protected]
the stop your development server and restart again
my resolution was to delete node_modules, install again the yarn
This is caused by @jridgewell/trace-mapping
- a dependency of @babel/core, You can update it to fix the problem.
Reference link:
[Bug]: Breaks react-router-dom #14229