question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Importing Leaflet Removes Dynamic Html Head on Build

See original GitHub issue

Reporting a bug

I am experiencing a rather weird situation using this genius library (please feel free to point me to the chat if it’s better suited there or even directly to the Leaflet community).

I am generating dynamic html information in the build stage which works absolutely fine however as soon as I import leaflet which we would like to use in our contact form it removes the head information and we just do not understand why.

Environment

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 736.20 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v10.17.0/bin/npm
  Browsers:
    Chrome: 80.0.3987.163
    Safari: 13.0.4

Steps to Reproduce the problem

  1. MVP can be found here git clone https://github.com/TimMcCauley/react-static-leaflet-head-bug.git
  2. yarn install
  3. yarn build && yarn serve
  4. Check the markup after building with and without line 3 in react-static-leaflet-head-bug/src/containers/Post.js
  5. With will strip out the dynamic Head and without react-helmet will build the html perfectly.

Expected Behavior

I would expect that importing leaflet would have no effect on the generation of the html head.

Reproducible Demo

https://github.com/TimMcCauley/react-static-leaflet-head-bug

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TimMcCauleycommented, Apr 22, 2020

@SleeplessByte you are a star… it finally WORKS, did exactly how you explained and it makes total sense. I updated the code in the repository:

https://github.com/TimMcCauley/react-static-leaflet-head-bug/blob/master/src/containers/Post.js

Cheers a bunch for this stunning hint!

/T

2reactions
SleeplessBytecommented, Apr 22, 2020

Given that src/core/Browser.js is targetting the browser – perhaps what you can try is conditionally import leaflet, for now. So basically, instead of doing:

import leafletthings from 'leaflet'

you only import it when in the browser (And not on build):

if (typeof document !== undefined) {
  import('leaflet').then(...)
  // or
  const leafletthings = require('leaflet')
}

If that makes it work, at least we know where to look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getting error on leaflet dynamic import on Next.js 10 #18336
After updating the project we are working on, we started to get a critical error on dynamic load level of leaflet. The important...
Read more >
85 - Stack Overflow
I got this error after upgrade react-leaflet to version 3.2.0 to fix an error while removing markers with permanent tooltips from the map....
Read more >
Integrating Next.js with Leaflet.js + Mapbox
Tutorial · Install the required dependencies · Creating the map component · Setting up Mapbox API · Adding a custom TileLayer to React...
Read more >
Use Dynamic Components to render HTML for 3rd party libraries
In this example we're going to learn how we can leverage dynamic Angular components to render the HTML of a popup controlled by...
Read more >
Plugins - Leaflet - a JavaScript library for interactive maps
The following plugins provide new ways of loading overlay data (GIS vector data): points, lines and polygons. Overlay data formats; Dynamic data loading ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found