-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte stores + web worker = global is not defined #4545
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
Comments
Out of curiosity, are you using webpack? I don't think the stores actually depend on anything in globals.ts, and in Rollup I believe it gets treeshaken away. |
I'm using Rollup and rollup-plugin-off-main-thread. I was hoping/expecting that globals would have gotten tree-shaken out, but for some reason that's not the case. I'll poke around some more. Thanks! |
So, I came across this issue again when spinning up a similar project. You can check it out here. In this project, I'm wanting to import a Svelte store in a Web Worker and load that Web Worker in a Svelte component. I'm using @surma's rollup-pugin-off-main-thread (OMT) to spin up that Web Worker (as a module, so that I can have access to imports in the Web Worker.) I'm also using Comlink to "expose" the Svelte store via an underlying Proxy object. In order to re-create the issue, there's a small bug in OMT that I need to report -- specifically commenting out a line in if (!isEsmOutput) {
// delete optionsObject.type;
} (This is due to how a config option is being parsed when Rollup is configured to output to an ES module.) Once you make that change and spin up the app, I'm getting the original error reported:
which references the below code in
Somehow globals are being sucked into the bundle. Changing Do you have any insight why globals isn't being tree-shaken out? Thank you! |
It appears that the export { get_store_value as get } from '../internal'; Can you confirm? |
Here's the issue that documents the bug in rollup-plugin-off-main-thread: surma/rollup-plugin-off-main-thread#22 |
store/index.ts is importing stuff from internal/index.ts which itself imports internal/globals.ts #3561 is somewhat related. |
Hm, so I tried to recreate the original issue to confirm the fix from #4628, but I'm no longer seeing |
In any case, in 3.21.0, we are now trying |
Having a similar issue. I'm using a web worker that imports from a module that imports from svelte/store. This is all via webpack and worker-loader, and it throws a const globals = (typeof window !== 'undefined'
? window
: typeof globalThis !== 'undefined'
? globalThis
: typeof global !== 'undefined'
? global
: self); |
Hello!
I'm trying to create a Svelte store in a Web Worker but am receiving this error:
This seems to occur in globals.ts. In spirit of #1491, can
window
be replaced withself
since Web Workers don't have access towindow
?The text was updated successfully, but these errors were encountered: