I’m adding a Mapbox map to a project, and it works on the first load, but if I reload the page I get an error from the console saying “SyntaxError: Identifier ‘map’ has already been declared” when it definitely hasn’t.
The weird thing is if I tweak the code in the HTML element, it works again on first load and then throws the same error if I reload the page.
If someone could explain why this is happening, that’d be awesome.
So does Bubble cache the html element or something? That’s the only thing I can think of as to why it would only throw that error when the page is reloaded.
Here’s my map box snippet if it helps:
In the HTML Header:
In the HTML Element:
// TO MAKE THE MAP APPEAR YOU MUST // ADD YOUR ACCESS TOKEN FROM // https://account.mapbox.com mapboxgl.accessToken = 'redacted'; const map = new mapboxgl.Map({ container: 'map', // container ID center: [-120.35, 50.675], // starting position [lng, lat] zoom: 12, // starting zoom });map.on('style.load', () => {
map.resize();
map.setConfigProperty('basemap', 'lightPreset', 'dusk');
});