gpt4 book ai didi

javascript - 无法读取未定义的属性(读取 'originalPositionFor' )

转载 作者:行者123 更新时间:2023-12-05 00:32:02 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





React Router: TypeError Cannot read properties of undefined (reading 'originalPositionFor')

(5 个回答)


6 个月前关闭。




我是react初学者,刚开始主题react-router-dom教程。
首先,我使用 npm i react-router-dom 安装了 react-router-dom
然后在 app.js 中,我使用函数 Header 中的默认代码并在 react-router-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 TRAINING\ReactRouter\node_modules\history\index.js: Cannot read properties of undefined (reading 'originalPositionFor')
at SourceMapTree.originalPositionFor (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@ampproject\remapping\dist\remapping.umd.js:159:27)
at trace (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@ampproject\remapping\dist\remapping.umd.js:102:37)
at EncodedSourceMapImpl.map (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@jridgewell\trace-mapping\dist\trace-mapping.umd.js:347:36)
at TraceMap.map (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@jridgewell\trace-mapping\dist\trace-mapping.umd.js:430:31)
at SourceMapTree.traceMappings (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@ampproject\remapping\dist\remapping.umd.js:85:34)
at remapping (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@ampproject\remapping\dist\remapping.umd.js:258:36)
at mergeSourceMap (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@babel\core\lib\transformation\file\merge-map.js:19:30)
at generateCode (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@babel\core\lib\transformation\file\generate.js:72:39)
at run (E:\REACT TRAINING\ReactRouter\my-app\node_modules\@babel\core\lib\transformation\index.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

关于javascript - 无法读取未定义的属性(读取 'originalPositionFor' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70965112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com