mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

V3 Upgrade: An error occurred while parsing the WebWorker bundle

Open devsheva opened this issue 1 year ago • 3 comments

mapbox-gl-js version: 3.8.0

browser: Chrome Version 130.0.6723.117

Steps to Trigger Behavior

  1. Upgrade to mapbox-gl v3
  2. Run the application

Link to Demonstration

https://jsbin.com/

Cannot easily provide a reproduction.

The application is a react app with webpack 4 and babel 8.

Expected Behavior

It should render the map after following the V3 migration guide.

Actual Behavior

An error occurred while parsing the WebWorker bundle

Screenshot 2024-11-20 at 17 26 48

This happens when importing with

import mapboxgl from 'mapbox-gl'

If i import with previous transpilation suggestion i get another error.

import mapboxgl from '!mapbox-gl'
./node_modules/mapbox-gl/dist/mapbox-gl.js 34:21870
Module parse failed: Unexpected token (34:21870)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

devsheva avatar Nov 20 '24 16:11 devsheva

@devsheva I'm seeing the same thing; how did you end up fixing this?

joelbrewer avatar Jan 30 '25 20:01 joelbrewer

Can you please upgrade to v3.9.4 and see if the problem still occurs?

mourner avatar Jan 30 '25 21:01 mourner

Sorry for not getting back here when i resolved my issue. I solved it by using the worker loader.


import MapboxWorker from 'worker-loader!mapbox-gl/dist/mapbox-gl-csp-worker'

// Load worker code separately with worker-loader

mapboxgl.workerClass = MapboxWorker // Wire up loaded worker to be used instead of the default

devsheva avatar Jan 31 '25 16:01 devsheva