类型错误模块“"react-leaflet"”没有导出成员'useEventHandlers'

Type error Module '"react-leaflet"' has no exported member 'useEventHandlers'

我有 nextjs 应用 + typescript + react-leaflet

当我启动我的开发服务器时 npm run dev 没问题,没有错误, 但是当我开始构建时 npm run build 我有一个错误,它说。

Type error: Module '"react-leaflet"' has no exported member 'useEventHandlers'.

  1 | import { useMemo, useCallback, useState } from 'react'
> 2 | import { useMap, useMapEvent, useEventHandlers, MapContainer } from 'react-leaflet'
    |                               ^
  3 |
  4 | // Classes used by Leaflet to position controls
  5 | const POSITION_CLASSES = {
info  - Checking validity of types .

这是我的 package.json 文件。

{
  "name": "spot-nearby",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@types/leaflet": "^1.7.0",
    "@types/react-leaflet": "^2.8.1",
    "axios": "^0.21.1",
    "csv-parser": "^3.0.0",
    "leaflet": "^1.7.1",
    "leaflet-geosearch": "^3.3.2",
    "next": "10.2.3",
    "papaparse": "^5.3.1",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-leaflet": "^3.2.0",
    "react-leaflet-search": "^2.0.1",
    "react-loader-spinner": "^4.0.0",
    "react-papaparse": "^3.14.0",
    "react-search-field": "^1.2.1"
  },
  "devDependencies": {
    "@types/react": "17.0.8",
    "typescript": "4.3.2"
  }
}

我已经安装了 @types/react-leaflet,但为什么会这样?

react-leaflet 实际上是 react-leaflet 软件包的 does not export useEventHandlers method. It's a method from @react-leaflet/core package. It's a dependency,并且必须与其一起安装。并且应该从那里导入:

import { useMap, useMapEvent, MapContainer } from 'react-leaflet'
import { useEventHandlers } from '@react-leaflet/core'