8000
Skip to content

jpeg and webp fail to import inside web worker #50

Description

@higbee4

Describe the bug
When I try to import jpeg or webp inside a web worker, I get this error:

⨯ ./node_modules/@jsquash/jpeg/codec/enc/mozjpeg_enc.js
Module parse failed: Identifier 'Module' has already been declared (5:12)
|     return function() {
|         let Module = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
>         var Module = typeof Module != "undefined" ? Module : {};
|         var readyPromiseResolve, readyPromiseReject;
|         Module["ready"] = new Promise(function(resolve, reject) {

avif and png both work though.

Solution
I noticed that avif and png use a slightly different syntax in the enc/dec files and they don't have this problem. I can work on a PR if preferred, or you can just change this inside jpeg/codec/enc/mozjpeg_enc.js, jpeg/codec/dec/mozjpeg_dec.js, webp/codec/enc/webp_enc.js, and webp/codec/dec/webp_dec.js to match the syntax used in avif and png that should fix it. I tried changing them locally and it fixed the problem for me.

Change

var Module = (() => {
  var _scriptDir = import.meta.url;
  
  return (
function(Module = {})  {

to

var Module = (function() {
  var _scriptDir = import.meta.url;
  
  return (
function(Module) {
  Module = Module || {};

Thanks.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

0