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

Using esbuild instead of Rollup fixes known terser bug #39

Open
zauni opened this issue Apr 12, 2022 · 5 comments
Open

Using esbuild instead of Rollup fixes known terser bug #39

zauni opened this issue Apr 12, 2022 · 5 comments

Comments

@zauni
Copy link
Contributor

zauni commented Apr 12, 2022

Hello @puzrin, locally I tried to build this library with esbuild instead of Rollup and this fixed the known issue with terser. Would you be interested in a PR to change the build from Rollup to esbuild?

Locally I built the ESM version with esbuild by issuing this command:
npx esbuild index.js --bundle --format=esm --outfile=dist/image-blob-reduce.esm.mjs and by using npm link I could try it out on a local project which is suffering from the terser bug, but as said with the esbuild version this bug did not appear.

The only problem with changing bundlers is that there could be other subtle problems coming up, but in my limited testing with the ESM version it was working just fine. But maybe you have more projects (best would be CJS projects) to test some new bundled versions.

Update: I saw that esbuild does not generate UMD bundles, so maybe these should be generated by Rollup like before. And just the ESM bundle which is also exported by the package.json will be generated by esbuild.

@non25
Copy link

non25 commented Mar 31, 2023

I've found that forcing source version by using patch-package yields good results without any effort. 🙂
nodeca/pica#228 (comment)

@nktka
Copy link

nktka commented May 8, 2023

Importing minified version in CRA fixes the issue.

I went from:

import p from 'image-blob-reduce';
const pica = p();

to:

import type { ImageBlobReduceStatic } from 'image-blob-reduce';
// @ts-ignore
import p from 'image-blob-reduce/dist/image-blob-reduce.min.js';
const pica = (p as ImageBlobReduceStatic)();

@Gkleinereva
Copy link

@nktka I get the following error when I try the solution that you suggest above

Error: Module not found: Error: Package path ./dist/image-blob-reduce.min.js is not exported from package /<projectRoot>/node_modules/image-blob-reduce (see exports field in /<projectRoot>/node_modules/image-blob-reduce/package.json)

Any ideas how I might circumvent this? I tried updating my terser config as suggested in the README, but I'm working in an NX/Angular project and I'm a webpack noob so I couldn't figure out how to do it :(

@nktka
Copy link

nktka commented Jun 22, 2024

@Gkleinereva that solution is for "create react app" so not applicable in your case. I'm sorry.

@Gkleinereva
Copy link

@nktka Thanks for your response :) For future explorers, I eventually ended up implementing the workaround documented at #17 (comment), which worked just fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants