PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.18k stars 887 forks source link

tsc throws an error as it can't find `@react-leaflet/core/lib/context` when `"module": "preserve"` is set in `tsconfig.json` #1141

Open 40thieves opened 3 months ago

40thieves commented 3 months ago

Bug report in v4

I'm running tsc with the preserve value for the module setting in tsconfig.json on a project with React Leaflet.

Expected behavior

No tsc errors are found.

Actual behavior

tsc throws the following errors:

node_modules/react-leaflet/lib/LayersControl.d.ts:9:65 - error TS2307: Cannot find module '@react-leaflet/core/lib/context' or its corresponding type declarations.

9     layerContainer?: import("leaflet").LayerGroup<any> | import("@react-leaflet/core/lib/context").ControlledLayer | undefined;
                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/react-leaflet/lib/LayersControl.d.ts:18:69 - error TS2307: Cannot find module '@react-leaflet/core/lib/context' or its corresponding type declarations.

18         layerContainer?: import("leaflet").LayerGroup<any> | import("@react-leaflet/core/lib/context").ControlledLayer | undefined;
                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/react-leaflet/lib/LayersControl.d.ts:30:69 - error TS2307: Cannot find module '@react-leaflet/core/lib/context' or its corresponding type declarations.

30         layerContainer?: import("leaflet").LayerGroup<any> | import("@react-leaflet/core/lib/context").ControlledLayer | undefined;
                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/react-leaflet/lib/SVGOverlay.d.ts:11:65 - error TS2307: Cannot find module '@react-leaflet/core/lib/context' or its corresponding type declarations.

11     layerContainer?: import("leaflet").LayerGroup<any> | import("@react-leaflet/core/lib/context").ControlledLayer | undefined;
                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 4 errors in 2 files.

Errors  Files
     3  node_modules/react-leaflet/lib/LayersControl.d.ts:9
     1  node_modules/react-leaflet/lib/SVGOverlay.d.ts:11

Steps to reproduce

I've made a minimal repro: https://github.com/40thieves/ts-react-leaflet which installs the relevant dependencies and configures tsconfig.json with the module: preserve setting. To reproduce, you need to:

  1. Clone & npm install
  2. Run npm run check

(apologies, I'm not sure StackBlitz would work as it's related to running tsc)