简体   繁体   English

未捕获的错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js)

[英]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:我努力了:

  • running babel-upgrade with npx使用 npx 运行 babel-upgrade
  • Adding babel.config.json with添加 babel.config.json 与
"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.为了以防万一,我什至关闭并重新启动了 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.这里有几个链接可能对像我这样没有意识到有变化的其他人有所帮助。

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.

相关问题 错误:模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误: - Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: 如何解决未捕获的错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js): - How to Solve Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): 错误 in./src/index.js 模块构建失败(来自./node_modules/babel-loader/lib/index.js): - ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js): 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js)Vue Js - Module build failed (from ./node_modules/babel-loader/lib/index.js) Vue Js 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js) - Module build failed (from ./node_modules/babel-loader/lib/index.js) 模块构建失败(来自./node_modules/babel-loader/lib/index.js): - Module build failed (from ./node_modules/babel-loader/lib/index.js): Webpack SyntaxError - 模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Webpack SyntaxError - Module build failed (from ./node_modules/babel-loader/lib/index.js) 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):错误:找不到模块“./src/data” - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module './src/data' 反应构建错误:模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): - React build error: Module build failed (from ./node_modules/babel-loader/lib/index.js): React 应用程序的编译错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Compile error for a React app: Module build failed (from ./node_modules/babel-loader/lib/index.js)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM