Reaction路由器:TypeError无法读取未定义的属性(正在读取'OriginalPositionFor')

React Router: TypeError Cannot read properties of undefined (reading #39;originalPositionFor#39;)(Reaction路由器:TypeError无法读取未定义的属性(正在读取#39;OriginalPositionFor#39;))

本文介绍了Reaction路由器:TypeError无法读取未定义的属性(正在读取'OriginalPositionFor')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是Reaction路由器的初学者,并使用Create-Reaction-app生成了基本源代码。

当我尝试根据教程设置路由器时,出现TypeError。 我试图减少任何可能导致问题的过多代码,直到我最终只得到了这个

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { Router } from 'react-router';

ReactDOM.render(
  <Router>
  </Router>,
  document.getElementById('root')
);

但我仍然收到相同的错误

    ERROR in ./node_modules/history/index.js
    Module build failed (from ./node_modules/babel-loader/lib/index.js):
    TypeError: /Users/Nanashi/reactjs/learning-my-blog/node_modules/history/index.js: Cannot read properties of undefined (reading 'originalPositionFor')
        at SourceMapTree.originalPositionFor (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@ampproject/remapping/dist/remapping.umd.js:159:27)
        at trace (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@ampproject/remapping/dist/remapping.umd.js:102:37)
        at EncodedSourceMapImpl.map (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js:347:36)
        at TraceMap.map (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js:430:31)
        at SourceMapTree.traceMappings (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@ampproject/remapping/dist/remapping.umd.js:85:34)
        at remapping (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@ampproject/remapping/dist/remapping.umd.js:258:36)
        at mergeSourceMap (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@babel/core/lib/transformation/file/merge-map.js:19:30)
        at generateCode (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@babel/core/lib/transformation/file/generate.js:72:39)
        at run (/Users/Nanashi/reactjs/learning-my-blog/node_modules/@babel/core/lib/transformation/index.js:55:33)
        at run.next (<anonymous>)
     @ ./node_modules/react-router/index.js 12:0-65 96:25-44 182:21-31 195:19-28 516:62-71 620:51-60 893:31-40 917:39-48 962:74-83
     @ ./src/index.js 8:0-38 10:38-44

    webpack 5.68.0 compiled with 1 error in 2579 ms

使用6.2.1版

    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router": "^6.2.1",
    "react-router-dom": "^6.2.1",
    "react-scripts": "5.0.0"

我完全摸不着头脑,任何帮助我都很感激。

编辑

我想我找到问题了。似乎babel/core@7.17.0发生了导致此问题的重大更改(https://github.com/aws-amplify/amplify-ui/issues/1242)。我使用了此注释中的解决方案https://github.com/aws-amplify/amplify-ui/issues/1242#issuecomment-1028471472,将我的依赖项设置为babel/core@17.16.12,错误消失

推荐答案

@jridgewell/trace-mapping包内有问题。

该问题已修复,并且新版本v0.2.3已发布。

如果您使用的是npm7+,则只需运行npm update就可以了。

这篇关于Reaction路由器:TypeError无法读取未定义的属性(正在读取&#39;OriginalPositionFor&#39;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Reaction路由器:TypeError无法读取未定义的属性(正在读取&#39;OriginalPositionFor&#39;)

基础教程推荐