-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Uncaught ReferenceError: n is not defined #228
Comments
I guess, this is known issue with minifier https://github.com/nodeca/image-blob-reduce#known-issues I can not debug your production bundling process, only explain principle. |
I tried that already, didn’t help. I even removed Terser from the webpack plugin chain completely, same issue. I‘ll try again and debug some more and see if I haven’t made a mistake in the config or understood something wrong about the webpack config. But it has to be something that is different between dev and prod build, so the minifier would be a hot tip. |
IMO, questions/discussions about external bundler tools are a bit out of this tracker scope. I can help only if something in |
Fair enough |
I'm closing this, but if you find anything to mention on readme - let me know. |
I'll just document my investigation process here until I find a solution. The runtime error is that variable
The source of this compiled code is this line in the pica dist: https://github.com/nodeca/pica/blob/master/dist/pica.js#L8
So somehow, webpack extracts The line is generated by browserify as far as I can tell, I'm not yet sure why browserify needs to check if |
Curiously,
And
So maybe there is a problem in how browserify creates the lib and how that interacts with webpack. |
Ok, so I'm using next.js 12 which should prioritize ES Modules over CommonJS.
|
I've added this question to the next.js ESM discussion thread: vercel/next.js#27876 (comment) |
I tried replacing |
Ok I was wrong about the ES version. It looks like the prod build does pick the ES version after all. I tested it by deleting the If the ES version is used, then the code fragment
So
This function is contained in my build output as
Prettified:
When the page initially loads, this code executes fine, also the What looks weird is that |
@puzrin I could get it to work, but not as-is. I needed to modify the
You can see the code changes here:
And this is the working image-blob-reduce esm module: https://github.com/fabb/image-blob-reduce/blob/pica-esm/dist/image-blob-reduce.esm.mjs I did not test the non-esm build outputs, so I don't know if they would still work as expected. Would you be interested in integrating these changes into your packages? The webworkify part would need to be figured out still, and the non-esm libs of image-blob-reduce would need to be tested. |
Ah I see you already tried to find an alternative for webworkify 😄 |
Yes, we stay with |
I understand. Too bad that combining browserify + rollup + webpack seems to be problematic 😅 |
That works. I don't know why you have problems.
At current moment i don't know good alternatives to existing approach. Everything was already considered. |
It might work with vanilla webpack, but not with vanilla next.js. I created a reproduction codesandbox with the default next.js 12 config: vercel/next.js#33452 It might be related to the webpack config that comes with next.js, I guess it‘s some issue with tree shaking since that is different between prod and dev builds in webpack. |
Coming here to say that I've got the same issue as @fabb . The best solution right now seems to be monkeypatching nextjs, which isn't great vercel/next.js#30924 |
I ended up using diff --git a/node_modules/image-blob-reduce/package.json b/node_modules/image-blob-reduce/package.json
index f5fcea1..6c66f3b 100644
--- a/node_modules/image-blob-reduce/package.json
+++ b/node_modules/image-blob-reduce/package.json
@@ -21,7 +21,7 @@
"./package.json": "./package.json",
"./lib/image_traverse.js": "./lib/image_traverse.js",
".": {
- "import": "./dist/image-blob-reduce.esm.mjs",
+ "import": "./index.js",
"require": "./index.js"
}
}, |
I use nextjs 14, this worked for me import ImageBlobReduce from "image-blob-reduce";
import Pica from "pica";
const pica = Pica({ features: ["js", "wasm", "cib"] });
const reduce = new ImageBlobReduce({ pica }); |
I'm using
image-blob-reduce
in a next.js app. In dev mode it works fine, but in prod mode, I get this error:It happens in the pica source:
I already tried turning off Terser, did not change anything.
Do you have any ideas what I could change to get this to work?
The text was updated successfully, but these errors were encountered: