react-leaflet
react-leaflet copied to clipboard
tsc throws an error as it can't find `@react-leaflet/core/lib/context` when `"module": "preserve"` is set in `tsconfig.json`
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.
- [x] All peer dependencies are installed: React, ReactDOM and Leaflet.
- [x] Using the latest version of React and ReactDOM v18.
- [x] Using the supported version of Leaflet (v1.8.0 minimum) and its corresponding CSS file is loaded.
- [x] Using the latest v4 version of React-Leaflet.
- [x] The issue has not already been reported.
- [x] Make sure you have followed the quick start guide for Leaflet.
- [x] Make sure you have fully read the documentation and that you understand the limitations.
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:
- Clone &
npm install - Run
npm run check
(apologies, I'm not sure StackBlitz would work as it's related to running tsc)