[Newcomer] Usage with Vite?

1097
1
Jump to solution
06-14-2022 05:21 AM
Benoit
by
New Contributor

Hello there,

I'm running a Vue3 app with ViteJS with Leaflet 1.7.1 and I'd like to use Esri's geocoding plugin https://developers.arcgis.com/esri-leaflet/geocode-and-search/search-for-an-address/

So I ran yarn add esri-leaflet esri-leaflet-geocoder esri-leaflet-vector but as `require()` doesn't exist in vite, I tried `import esri from 'esri-leaflet'` instead but it doesn't work, since the lib doesn't provide a default export.

Example:

<script setup>
import L from 'leaflet';
import esri from 'esri-leaflet';
// ...
</script>

 

Any idea what / how to import the library in a Vite context?

Thanks!

Ben

0 Kudos
1 Solution

Accepted Solutions
GavinRehkemper
Esri Contributor

Hi, thanks for the question.

I think you want to import the named module, like this:

import { FeatureLayer } from "esri-leaflet";
import { vectorBasemapLayer } from "esri-leaflet-vector";

 https://github.com/gavinr/esri-leaflet-react-demo/blob/90f910ec5a45f56089853eff437b353c73457fff/src/...

 

 

View solution in original post

1 Reply
GavinRehkemper
Esri Contributor

Hi, thanks for the question.

I think you want to import the named module, like this:

import { FeatureLayer } from "esri-leaflet";
import { vectorBasemapLayer } from "esri-leaflet-vector";

 https://github.com/gavinr/esri-leaflet-react-demo/blob/90f910ec5a45f56089853eff437b353c73457fff/src/...