React-leaflet: Module not found: Can't resolve 'leaflet'

Created on 23 Jun 2018  路  18Comments  路  Source: PaulLeCam/react-leaflet

When I do like I am currently facing this error,

./node_modules/react-leaflet/es/Marker.js
Module not found: Can't resolve 'leaflet' in ...\node_modules\react-leaflet\es'

Most helpful comment

I ran into the same error, you need to add 'leaflet' to your depencies :
yarn add leaflet
npm i leaflet

All 18 comments

I ran into the same error, you need to add 'leaflet' to your depencies :
yarn add leaflet
npm i leaflet

I did it truely!
still this error. even when I ctrl+click on the file names , it goes to the file inner!

Facing the same issue here.
Using Webpack 4.12 and Typescript 2.9.2 with react-leaflet 2.0.0-rc.2"

yarn add leaflet worked for me

Does not work for me; same error.
Using "react-leaflet": "^2.0.0" in packages.json
Module not found: Can't resolve 'leaflet' in '/home/.../..../...../client/node_modules/react-leaflet/es'

same

Still no solution? I'm getting the same error:
'Can't resolve 'leaflet' in '/home/.../..../...../client/node_modules/react-leaflet/es''

yarn add leaflet // npm i leaflet --> didn't help

worked for me!

npm install react-leaftlet --save then
npm i leaflet

To clarify for anyone reading, react-leaflet has react, react-dom, and leaflet as peerDependencies which means they have to be npm installed separately or you will get this error. This is in fact noted on the installation instructions in the docs: https://react-leaflet.js.org/docs/en/installation.html

I would recommend doing --save on all the dependencies too, but that may depend on your use case.

worked for me!

npm install react-leaftlet --save then
npm i leaflet

This order worked for me. Thanks.

Make sure you install in the right folder.

// Someone who didn't install in the right folder.

To avoid this issue, I think leaflet should be a peer of react-leaflet.

Can you use react-leaflet without leaflet? I am unclear why it is a peer dependency and not a dependency.

@jjsmclaughlin It's a peer. But you have to install it to your project.

From the docs:

React, ReactDOM and Leaflet are peer dependencies, if you haven't already installed them you can use:

npm install leaflet react react-dom # npm
yarn add leaflet react react-dom # Yarn

I faced the problem. Then this command solve my problem.. ###
$ npm i leaflet

I got the same error. I needed to install the leaflet package but also include the leaflet CSS file from the CDN.

_yarn add leaflet_ worked for me too!

worked for me!

npm install react-leaftlet --save then
npm i leaflet

Worked for me,
thank you

Was this page helpful?
0 / 5 - 0 ratings