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

fix(worker): non module worker in production #4741

Closed
wants to merge 1 commit into from
Closed

fix(worker): non module worker in production #4741

wants to merge 1 commit into from

Conversation

mathe42
Copy link
Contributor

@mathe42 mathe42 commented Aug 26, 2021

Description

fixes #4586

In production to do the iife build is so the worker can run in all browsers. But this only works if the worker is then not createt as a module.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@mathe42 mathe42 mentioned this pull request Aug 26, 2021
7 tasks
@mathe42 mathe42 changed the title fix (worker): non module worker in production fix(worker): non module worker in production Aug 26, 2021
@mathe42
Copy link
Contributor Author

mathe42 commented Aug 27, 2021

This dosn't fix anything. I think it is best practice to change it (as for example chrome fails when useing type: 'worker' for serviceWorker wich is not supported not shure if other browsers also have a early error when type: 'worker' is not supported.

But feel free to close this PR if not needed.

(Note: sometimes you need a non chromium browser to check how different code fails)

@Monkatraz
Copy link
Contributor

Monkatraz commented Sep 13, 2021

No, this PR does fix an obvious bug. Workers are fully bundled under IIFE, but still have { type: "module" } in production, which is pointless.

@mathe42
Copy link
Contributor Author

mathe42 commented Sep 13, 2021

Note that Firefox ignores the type option so setting it is ignored.

@Pinpickle
Copy link

I'll chime in and say this does fix a bug in certain versions of Chrome where module workers were still experimental and behind a flag. It sees the { type: 'module' } argument and throws an error, prompting the reader to enable module workers in a flag (even though the worker script itself doesn't use modules).

I don't have the error report handy, but I think it might have been Chrome version 74 in the wild.

@mathe42
Copy link
Contributor Author

mathe42 commented Dec 6, 2021

Yes agreed this should be Changes!

@Pinpickle
Copy link

Is there anything blocking this from getting merged? I'm getting crash reports of workers failing because of this. Tagging @Shinigami92 as I see you added a label to this PR.

The specific error is Failed to construct 'Worker': Module scripts are not supported on DedicatedWorker yet. You can try the feature with '--enable-experimental-web-platform-features' flag (see https://crbug.com/680046) which I've seen reported on versions of Chrome version 79 and under.

@sapphi-red
Copy link
Member

Closing as it is currently able to use classic workers.
https://vitejs.dev/guide/features.html#import-with-constructors
https://vitejs.dev/config/#worker-options

@sapphi-red sapphi-red closed this Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import statement in Workers
5 participants