如何重现:
- 运行以下命令创建 React 项目并安装依赖:
npx create-react-app example --template typescript
cd example
npm i @uiw/react-baidu-map
- 将以下代码粘贴到
src/App.tsx:
import './App.css';
import {
Map, APILoader,
} from '@uiw/react-baidu-map';
const Demo = () => (
<div style={{ width: '100%', height: '1000px', overflow: 'auto' }}>
<APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG">
<Map
zoom={13}
style={{ height: 1000 }}
enableScrollWheelZoom={true}
enableContinuousZoom={true}
>
</Map>
</APILoader>
</div>
);
function App() {
return <Demo></Demo>
}
export default App;
- 运行
npm start
当用户用鼠标滚轮放大地图会抛出 Uncaught TypeError: Cannot read properties of undefined (reading 'style') 并显示:

如果 npm run build 并用生产版本运行不会出现这个问题。