-
Notifications
You must be signed in to change notification settings - Fork 56
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
Error with es6 worker + es6 modules #111
Comments
btw, this is how I import the code, the docs tell me that a import 'https://unpkg.com/d3-delaunay@5.3.0/dist/d3-delaunay.js';
console.log(d3); but I never reach my console log due to the error |
This comment has been minimized.
This comment has been minimized.
test.html <script type="module">
await CSS.paintWorklet.addModule('gradient.js');
</script> gradient.js import 'https://unpkg.com/d3-delaunay@5.3.0/dist/d3-delaunay.js';
console.log(d3); Throws the error, because workers and/or worklets do not have a global variable |
aah correction, worklets specifically, workers work fine. this creates a worker, and works as intended <script type="module">
const w = new Worker('gradient.js', { type: 'module' });
</script> where as my previous comment creates a worklet, which gives the error of the |
hmmm I wonder if upgrading rollup would suffice? It's something that's yet to deploy in all the modules. |
can I possibly bother you with the question of quickly making a build with the new rollup? or is that not feasible? |
I have a simpler test: import 'https://unpkg.com/d3@6';
console.log(d3); // {the d3 object} 👍 import 'https://unpkg.com/d3@5';
console.log(d3); // ReferenceError: self is not defined 💣 So I guess the next releases will work. In the meantime you might want to load d3@6 |
Related: d3/d3#3366 |
Thanks!!! works like a charm! |
leaving open so I'll be happier to close it with the proper dependency upgrade :) |
ok. :D |
Oh oh! You would do https://observablehq.com/@fil/walk-on-spheres-worker in gradient.js? |
Should be fixed by #113 |
sorry for the late response, I seem to have overlooked this on my vacation. I don't believe I would use the tatic used in your link as the 2dcontext provided by a paintworklet, while intended to be similar, is not the same as a canvas. One of the differences is no ability to draw pixel per pixel. In this case meaning that I need some nasty workaround to calculate each pixels color based on a polygon somehow. my current thinking is to use what I have above and then somehow place some linear gradients on the edges. |
Your approach made me curious about this spec and I wrote a helper function to create and update paintworklets https://observablehq.com/@fil/hello-paintworklet |
nice! thanks for the mention :D Maybe I'll make a post if / when I actually manage to make this gradient shader without per-pixel calculations :P |
fixed in d3-delaunay@6 |
Hi,
I'm getting the following error when trying to include your lib in js worker (paint-worklet to be exact).
Can you either chain and or change the
self
toglobalThis
(is supported by all relevant browsers as far as I am aware).Or even better, if I can bother you with this job, create a delaunay.min.esm so I can just use es6 modules as is :D
Thanks in advance!!!
The text was updated successfully, but these errors were encountered: