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

Lib throws error when imported inside a service worker #449

Closed
rodgobbi opened this issue Jul 2, 2018 · 4 comments · Fixed by #463
Closed

Lib throws error when imported inside a service worker #449

rodgobbi opened this issue Jul 2, 2018 · 4 comments · Fixed by #463

Comments

@rodgobbi
Copy link

rodgobbi commented Jul 2, 2018

Currently on the project that I'm working on, there's a build process for the service worker used in the application, and one of the files used by the service worker is importing the lib, although the lib is not used inside the service worker, it throws an error when executing the service worker script, which is:

TypeError: Cannot read property 'createElementNS' of undefined

@rodgobbi
Copy link
Author

rodgobbi commented Jul 2, 2018

Analyzing the code I can guess that the expression typeof self !== "undefined" && self is returning true and the self reference to the service worker, but the service worker context is different from the window.
I can help with any implementation and testing if it's desired for the lib to work on this use case.

@jimmywarting
Copy link
Collaborator

Filesaver don't work in service workers. Why do include it there?

@rodgobbi
Copy link
Author

rodgobbi commented Jul 5, 2018

It's mainly because it breaks the SW registration if a file used by the SW imports the lib, even if it's not being used inside the SW.
I understand, no explicit need to mind this issue, but anyone using the lib in a project which has a SW at the same project needs to be aware of this caveat.

@stsiarzhanau
Copy link

stsiarzhanau commented Jul 30, 2018

Hi! Currently our team is working on a big react-redux based project. We have the same error and it totally breaks our worker based calculations. Note, that we don't import 'file-saver' directly into worker script, it happens through the chain of other imports (about 15). For now I just fixed it by moving one util to different module to break that chain. But it took some time to find out what happens. So it'd be great if such a scenario was taken into account when releasing the next version. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants