catdad-experiments / heic-convert

🤳 convert heic/heif images to jpeg and png
252 stars 26 forks source link

Uncaught TypeError: util.inherits is not a function #29

Closed ralphvirtucio closed 11 months ago

ralphvirtucio commented 1 year ago

Hi there,

I'd like to report an issue. After installing 'heic-convert' in my Vue project and attempting to import it into my components, I encountered the following error: "Uncaught TypeError: util.inherits is not a function." Could you please provide insights into the cause of this error?

catdad commented 1 year ago

No immediate guesses. I don't have a readily available vue project. Do you have a minimal repro example for this?

vladimir-djokic-quantox commented 12 months ago

I have stumbled upon this issue as well in a React project. You can view the demo here https://stackblitz.com/edit/vitejs-vite-cqulcz?file=src%2Fcomponents%2FUploader.tsx

Screenshot 2023-11-15 at 14 43 44
catdad commented 11 months ago

So this is actually a vite issue, and has nothing to do with what framework vite is building. Googling this error easily finds a whole slew of solutions, likely the best one being just using the vite-plugin-node-polyfills plugin.

However, I can do one better. pngjs and jpeg-js are used to encode the result images, and are both decently sized modules. However, when building a client-side application, they really are not needed, since all browsers already have built-in png and jpeg encoders. So in version 2.1.0, I made these encoders optional, and when building a client-side application, you can require('heic-convert/browser') to use the browser's built-in encoders and leave pngjs and jpeg-js out of your final bundle. See #33 for more if you are curious.