You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Thanks for your patience @higbee4. I've taken a look at it now and cannot reproduce it.
The issue is happening as it appears you have some kind of preprocessor/module bundler that is modifying the package code. The issue is that it's modified the code and tried to define Module with let and then again with var hence the error.
If you are using Vite or Nuxt we recommend disabling transpilation of jsquash modules (See the note in the README)
If you can help with following it help us solve the issue quicker:
Which version of the packages are you using?
Which module bundler are you using? (Webpack, Vite etc.)
Describe the bug
When I try to import jpeg or webp inside a web worker, I get this error:
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
, andwebp/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
to
Thanks.
The text was updated successfully, but these errors were encountered: