ericnograles / browser-image-resizer

A tiny browser-based library to downscale and/or resize images using canvas
MIT License
99 stars 43 forks source link

NodeJS https module dependency in latest version #67

Closed jz222 closed 2 years ago

jz222 commented 2 years ago

Hi,

thanks for this package.

I'm using it in a React app with the standard create-react-app config. Since version v2.2.1 of browser-image-resizer, the React app doesn't compile with the following error:

ERROR in ./node_modules/browser-image-resizer/dist/index.js 3476:52-72

Module not found: Error: Can't resolve 'https' in '/Users/user/dev/frontend-futura/node_modules/browser-image-resizer/dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
    - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "https": false }

I understand the error and know how to fix it, but I was wondering if it's necessary to have this https depedency that requires me to add a polyfill.

Thanks for your time

ericnograles commented 2 years ago

Hi @jz222 as the error message states, the package uses Webpack 4.x so by default it includes the https polyfill. I'll see how big of a lift it is to go to webpack 5.x.

ericnograles commented 2 years ago

Was able to bump to Webpack 5 with minimal drama, will deploy a 2.4.x line of the library with this change and hopefully that gets rid of that error in CRA, I will do a manual test after to verify.

ericnograles commented 2 years ago

So bad news here, exif-reader injects these Node modules by default, so we're getting caught in the blast radius here. As a workaround, add https, http, and fs polyfills in your CRA. Sorry for the inconvenience!

ericnograles commented 2 years ago

@jz222 so great news, because we were able to nuke the exifreader dependency, this is no longer an issue. Please install 2.4.0 from npm and you should be all set -- see PR #70

Thanks!

jz222 commented 2 years ago

Thanks a lot for the update, it works fine now.