gpt4 book ai didi

javascript - react 路由器 : TypeError Cannot read properties of undefined (reading 'originalPositionFor' )

转载 作者:行者123 更新时间:2023-12-05 00:31:04 24 4
gpt4 key购买 nike

嗨,我是 React Router 的初学者,并使用 create-react-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你应该没事。

关于javascript - react 路由器 : TypeError Cannot read properties of undefined (reading 'originalPositionFor' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70965180/

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