[英]Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js)
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.
我使用 Create-React-App 构建了应用程序,因此我不必考虑 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...
该错误相当长,但这是 bundle.js 错误的第一部分......
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.该应用程序是前端的 React 和后端的.Net Core。 I start the SPA from startup.cs with...
我从 startup.cs 开始 SPA...
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
I have tried:我努力了:
"presets": ["@babel/preset-env", "@babel/preset-react"]
"@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.
为了以防万一,我什至关闭并重新启动了 VS Code。 Any thoughts on how to fix would be appreciated.
任何关于如何修复的想法将不胜感激。
I 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.
虽然显示的错误将我指向 Babel,这是我的想法,但真正的问题与 React 路由的更改有关。
I had to wrap all my <route>
elements in a <Routes>
tag.我必须将所有
<route>
元素包装在<Routes>
标记中。 I then had to change the component attribute to element and place the component in html-like syntax...from {Home}
to {<Home/>}
.然后我不得不将组件属性更改为 element 并将组件放在类似 html 的语法中......从
{Home}
到{<Home/>}
。
One other change was that my import was pulling from react-router.另一个变化是我的导入是从 react-router 中提取的。 I changed it to react-router-dom.
我将其更改为 react-router-dom。
This was all in my App.js.这一切都在我的 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://dev.to/gabrlcj/react-router-v6-some-of-the-new-changes-181m
https://www.c-sharpcorner.com/article/react-router-v6-what-changed-and-upgrading-guide/ https://www.c-sharpcorner.com/article/react-router-v6-what-changed-and-upgrading-guide/
This is caused by @jridgewell/trace-mapping
- a dependency of @babel/core, You can update it to fix the problem.这是由
@jridgewell/trace-mapping
引起的 - @babel/core 的依赖项,您可以对其进行更新以解决问题。 Reference link: [Bug]: Breaks react-router-dom #14229参考链接: [Bug]: Breaks react-router-dom #14229
This error comes when you install the latest version of npm like this npm install react-router-dom@6 after running npm start it will fail to compile because of @babel/core is incompatible with the npm version so you have to revert back to babel previous versions run this: This error comes when you install the latest version of npm like this npm install react-router-dom@6 after running npm start it will fail to compile because of @babel/core is incompatible with the npm version so you have to revert back to babel 以前的版本运行这个:
npm i -D @babel/core@7.16.12 npm i -D @babel/core@7.16.12
the stop your development server and restart again停止您的开发服务器并重新启动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.