Home > front end >  Cannot read properties of undefined (reading 'originalPositionFor')
Cannot read properties of undefined (reading 'originalPositionFor')

Time:02-03

I am a beginner to react, just started the topic react-router-dom tutorials. Firstly I installed the react-router-dom using npm i react-router-dom Then in app.js I use the by-default code in the function Header and call this element in the react-router-dom structure:

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>
  );
  
}

and when I start the server using npm start I got this error:

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)

 

I tried to find various sources bt not able to find any solutiion.

Dependencies: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" }

CodePudding user response:

Downgrade @babel/core to previous version which fixed it for me

npm i -D @babel/[email protected]

CodePudding user response:

I'm also stuck into this. When importing BrowserRouter.

CodePudding user response:

Downgrade [email protected] working for me.

npm i [email protected]

CodePudding user response:

Try @babel/[email protected] with no caret (^). It seems like the latest (7.17.0) that was released today is broken.

  •  Tags:  
  • Related