Skip to content
Advertisement

How to fix error “Failed to compile : ./node_modules/@react-leaflet/core/esm/path.js 10:41 Module parse failed: Unexpected token (10:41)”

I am trying to create a react-typescript app along with leaflet. I used the command,

npm install leaflet react-leaflet @types/react @types/leaflet --save to install the dependencies.

But when I start the application it says,

JavaScript

Here’s my package.json

JavaScript

Here’s map/index.tsx

JavaScript

I tried reinstalling dependencies several times but still didn’t work.

I understand this is a simple issue and an error that I am making but however, I have not been able to resolve this error.

Advertisement

Answer

I found a way to fix it.

Steps to fix:

Open your package.json file and edit your browserslist as follows.

From ?? Operator results in “Unexpected Token” err when used in package #9468:

JavaScript

to

JavaScript

Once you’ve done this, delete the node_modules/.cache directory.

Then try npm install.

And npm start

Tadaaa!

References:

Advertisement