catdad-experiments / heic-convert

šŸ¤³ convert heic/heif images to jpeg and png

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError: util.inherits is not a function

ralphvirtucio opened this issue Ā· comments

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?

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

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

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.