Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workerUrl for csp not working in esbuild #1550

Closed
httpete opened this issue Aug 25, 2022 · 5 comments
Closed

workerUrl for csp not working in esbuild #1550

httpete opened this issue Aug 25, 2022 · 5 comments
Labels
invalid This doesn't seem right

Comments

@httpete
Copy link

httpete commented Aug 25, 2022

Hi,

esbuild yells at us if we try to do

maplibregl.workerUrl = "path/to/worker.js"

"cannot assign to import"

It looks like MapBoxGL lets you assign a workerclass instead of a url. Can yours do that?

@HarelM
Copy link
Collaborator

HarelM commented Aug 26, 2022

We'll need more info in order to understand what you mean... Please provide code pen of both options.
In theory (assuming we haven't break this), this should work as it did in mapbox 1.13.

@HarelM HarelM added the need more info Further information is requested label Aug 26, 2022
@httpete
Copy link
Author

httpete commented Aug 26, 2022

Thanks @HarelM

So MapBox has: https://docs.mapbox.com/mapbox-gl-js/api/properties/#workerclass

It is specifically designed to do what I am saying. We use esbuild, and the distribution you have of the

https://unpkg.com/browse/maplibre-gl@2.3.0/dist/maplibre-gl-csp.js

Only ships an IFFE / UMD version. It would be better if you could distribute multiple package formats, so we can slowly move to ESM.

Here, there is a thread describing why. It breaks ESM principles to use the gl.workerUrl = "" method of setting.

evanw/esbuild#891

The other alternative is to provide another way to set the worker url or worker class without the = assignment, so it can work with ESM bundlers. esbuild is a huge player in the space today.

@httpete
Copy link
Author

httpete commented Aug 26, 2022

The way to reproduce this is to simply try to use the sample csp mgl.workerUrl= "" method in a project that uses esbuild. Anyone will hit this error.

@HarelM
Copy link
Collaborator

HarelM commented Aug 26, 2022

This is still to vague. Can you please create a stackblitz reproduction?

@httpete
Copy link
Author

httpete commented Aug 26, 2022

After review, I found that if you import it via:

import maplibreGl from "maplibre-gl/dist/maplibre-gl-csp";
maplibreGl.workerUrl = '/js/webworker.js';

it works. But if you do this:

import * as maplibreGl from "maplibre-gl/dist/maplibre-gl-csp";

maplibreGl.workerUrl = '/js/webworker.js';

It doesn't.

@httpete httpete closed this as completed Aug 26, 2022
@HarelM HarelM added invalid This doesn't seem right and removed need more info Further information is requested labels Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants