Cannot read properties of undefined (reading #39;originalPositionFor#39;)(无法读取未定义的属性(正在读取#39;OriginalPositionFor#39;))
问题描述
我是反应的初学者,刚刚开始讨论反应-路由器-避孕套教程。
首先,我使用npm i react-router-dom
安装了REACTION-ROUTER-DOM
然后,在app.js中,我在函数头中使用默认代码,并在act-route-dom结构中调用此元素:
import logo from './logo.svg';
import './App.css';
import { BrowserRouter as Router,Routes,Route} from "react-router-dom";
function App() {
return (
<Router>
<Routes>
<Route path="/" element={<Header />} />
</Routes>
</Router>
);
}
export default App;
function Header(){
return(
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>Edit <code>src/App.js</code> and save to reload.</p>
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
Learn React
</a>
</header>
</div>
);
}
当我使用npm start
启动服务器时,收到以下错误:
log.js:59 Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: E:REACT TRAININGReactRouter
ode_moduleshistoryindex.js: Cannot read properties of undefined (reading 'originalPositionFor')
at SourceMapTree.originalPositionFor (E:REACT TRAININGReactRoutermy-app
ode_modules@ampproject
emappingdist
emapping.umd.js:159:27)
at trace (E:REACT TRAININGReactRoutermy-app
ode_modules@ampproject
emappingdist
emapping.umd.js:102:37)
at EncodedSourceMapImpl.map (E:REACT TRAININGReactRoutermy-app
ode_modules@jridgewell race-mappingdist race-mapping.umd.js:347:36)
at TraceMap.map (E:REACT TRAININGReactRoutermy-app
ode_modules@jridgewell race-mappingdist race-mapping.umd.js:430:31)
at SourceMapTree.traceMappings (E:REACT TRAININGReactRoutermy-app
ode_modules@ampproject
emappingdist
emapping.umd.js:85:34)
at remapping (E:REACT TRAININGReactRoutermy-app
ode_modules@ampproject
emappingdist
emapping.umd.js:258:36)
at mergeSourceMap (E:REACT TRAININGReactRoutermy-app
ode_modules@babelcorelib ransformationfilemerge-map.js:19:30)
at generateCode (E:REACT TRAININGReactRoutermy-app
ode_modules@babelcorelib ransformationfilegenerate.js:72:39)
at run (E:REACT TRAININGReactRoutermy-app
ode_modules@babelcorelib ransformationindex.js:55:33)
at run.next (<anonymous>)
at Object.../node_modules/history/index.js (http://localhost:3000/static/js/bundle.js:41373:7)
at Object.options.factory (http://localhost:3000/static/js/bundle.js:46449:31)
at __webpack_require__ (http://localhost:3000/static/js/bundle.js:45899:33)
at fn (http://localhost:3000/static/js/bundle.js:46120:21)
at Module.../node_modules/react-router-dom/index.js (http://localhost:3000/static/js/bundle.js:41527:65)
at Module.options.factory (http://localhost:3000/static/js/bundle.js:46449:31)
at __webpack_require__ (http://localhost:3000/static/js/bundle.js:45899:33)
at fn (http://localhost:3000/static/js/bundle.js:46120:21)
at Module../src/App.js (http://localhost:3000/static/js/bundle.js:68:74)
at Module.options.factory (http://localhost:3000/static/js/bundle.js:46449:31)
我尝试查找各种来源,但找不到任何解决方案。
依赖项:dependencies": { "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^13.5.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "5.0.0", "web-vitals": "^2.1.4" }
推荐答案
将@babel/core降级到以前的版本,已为我修复了该问题
npm i -D @babel/core@7.16.12
这篇关于无法读取未定义的属性(正在读取';OriginalPositionFor';)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法读取未定义的属性(正在读取';OriginalPositionFor';)
基础教程推荐
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 动态更新多个选择框 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06