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

Trailing Comma in the LoaderOption causes SyntaxError on removing type:module #25

Closed
lacolaco opened this issue Mar 24, 2019 · 5 comments · Fixed by #49
Closed

Trailing Comma in the LoaderOption causes SyntaxError on removing type:module #25

lacolaco opened this issue Mar 24, 2019 · 5 comments · Fixed by #49
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@lacolaco
Copy link
Contributor

lacolaco commented Mar 24, 2019

At first, I think this is not only by the WorkerPlugin's implementation.

Problem

When {type: 'module'} contains trailing-comma like below, compiled JavaScript is broken.

// pre-compile
new Worker('./foo.js', { 
  type: 'module',
});
// post-compile
new Worker('./foo.js', { 
  , // <--- SyntaxError
});

Workaround

Removing the comma.

 new Worker('./foo.js', { type: 'module' });

Version

I confirm reproducing in v3.0.0 and v3.1.0.

@lacolaco
Copy link
Contributor Author

This can happen frequently if developers are using code formatter like Prettier.

@developit
Copy link
Collaborator

ooof! good catch.

@viceice
Copy link

viceice commented Jul 3, 2019

the same is happen if you use additional options like:

new Worker('./monaco-css.worker', { type: 'module', name: 'monaco-css' });

My current Workaround is to flip type as last property.

Why preserveTypeModule is undefined by default? should not type be preserved by default?

@developit
Copy link
Collaborator

@viceice preserving {type:'module'} forces the worker code into strict mode by default, which is unexpected given it's being used to load CommonJS webpack output. I believe there are also environments in which { type: 'module' } throws when passed to Worker().

@developit
Copy link
Collaborator

If anyone has a deep working knowledge of Webpack's funky parser modifiers, this is the line that replaces type:'module' with an empty expression. Maybe it needs to be null? I have no idea.
https://github.com/GoogleChromeLabs/worker-plugin/blob/master/src/index.js#L79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants