react-leaflet on an application with typescript

Viewed 642

I have a react application which I created using the create-react-app tool, the application uses typescript , after importing the create-react-app and the typescript library '@types/leaflet' my application fails to build with the following error message:

Failed to compile. 
node_modules/@react-leaflet/core/types/index.d.ts TypeScript error in .../node_modules/@react-leaflet/core/types/index.d.ts(3,1):
Declaration or statement expected.  TS1128

    1 | export { useAttribution } from './attribution';
    2 | export { updateCircle } from './circle';
  > 3 | export type { CircleMarkerProps } from './circle';
      | ^
    4 | export { createContainerComponent, createDivOverlayComponent, createLeafComponent, } from './component';
    5 | export { CONTEXT_VERSION, LeafletContext, LeafletProvider, useLeafletContext, } from './context';
    6 | export type { LeafletContextInterface } from './context';

Any idea how to fix?

2 Answers

I upgrade my Typescript version in the package.json from 3.4.3 to 4.1.2 and the error disappeared.

I had the same issue and posted it here on the React-Leaflet GitHub https://github.com/PaulLeCam/react-leaflet/issues/798.

As mentioned by Toni Spock, the Typescript version is causing this.

The issue is that the import/export feature isn't available until Typescript 3.8. So upgrading the Typescript version to latest should resolve this.

Related