# Trouble when refresh a notebook with leaflet

**URL:** <https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817>\
**Category:** Help\
**Created:** [November 15, 2021, 2:21pm UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817 "2021-11-15T14:21:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbbarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jbbarre/32/4890_2.png) [@jbbarre](https://talk.observablehq.com/u/jbbarre)\
**Post date:** [November 15, 2021, 2:21pm UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/1 "2021-11-15T14:21:02Z")

</div>

Hello,  
In my new notebook [antarctica-leaflet](https://observablehq.com/@jbaba/antarctica-leaflet), after a refresh, I encouter this error message: _map2 = TypeError: Cannot read properties of undefined (reading ‘CRS’)_  
To display the map, I need to play the cell where `map2` is defined . It seems to be linked to the “require” of L[proj] but I can’t figure out how to solve this.

Any suggestion is welcome. Thank you.  
jb

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [November 15, 2021, 2:31pm UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/2 "2021-11-15T14:31:04Z")

</div>

`L.Proj` is not part of the standard Leaflet distribution; rather, you’ve added it on in the penultimate cell, which looks like so:

```
(L["Proj"] = await require("https://cdnjs.cloudflare.com/ajax/libs/proj4leaflet/1.0.2/proj4leaflet.min.js"))

```

You can simply name that cell and then insert that name into the definition of `map2` to ensure that `L.Proj` is defined when `map2` runs. Here’s an example:

> **[Antarctica | Leaflet](https://observablehq.com/d/bee0ec7782151f0f)**
>
> Leaflet and ObservableHQ We’ll need a compatible set of tiles for the EPSG:3031 projection. The ones hosted by the Global Biodiversity Information Facility are perfect. The map tile url pattern is given on that page as:...

---

<div class="post-metadata">

**Author:** ![jbbarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jbbarre/32/4890_2.png) [@jbbarre](https://talk.observablehq.com/u/jbbarre)\
**Post date:** [November 15, 2021, 4:54pm UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/3 "2021-11-15T16:54:38Z")

</div>

Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [November 16, 2021, 12:10am UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/4 "2021-11-16T00:10:40Z")

</div>

As a perhaps “cleaner” alternative you can pass the `leaflet` dependency to `proj4leaflet` via `require.alias`:

```auto
L = {
  const L = await require("leaflet@1");
  await require.alias({leaflet: L})("proj4leaflet@1.0.2");
  // ...
  return L;
}

```

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [November 16, 2021, 12:20am UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/5 "2021-11-16T00:20:49Z")

</div>

There’s also no need to store a reference to the link element if you remove it when the cell is invalidated. With all of these changes applied, the final code could look like this:

```auto
L = {
  // Resolve base URL once to avoid additional requests.
  // "." at the end prevents d3-require from appending ".js"
  const base = await require.resolve("leaflet@1/dist/.");
  const style = document.head.appendChild(html`<link href="${base}/leaflet.css" rel=stylesheet>`);
  // Remove <link> element when this cell is rerun.
  invalidation.then(() => style.remove());
  
  const L = await require(`${base}/leaflet.js`);
  await require.alias({leaflet: L})("proj4leaflet@1.0.2");
  return L;
}

```

---

<div class="post-metadata">

**Author:** ![jbbarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jbbarre/32/4890_2.png) [@jbbarre](https://talk.observablehq.com/u/jbbarre)\
**Post date:** [November 16, 2021, 6:48am UTC](https://talk.observablehq.com/t/trouble-when-refresh-a-notebook-with-leaflet/5817/6 "2021-11-16T06:48:08Z")

</div>

I now see better how to deal with. thank you very much.
