Skip to content

Conversation

@jhon2c
Copy link

@jhon2c jhon2c commented Jan 14, 2026

Problem

When using the web worker version in Next.js projects, users encountered a persistent error:

Conversion failed: k.toBlob is not a function

The next version (src/next/index.js) uses OffscreenCanvas instead of regular HTMLCanvasElement to support server-side rendering and web workers. However, the code was calling canvas.toBlob(), which is only available on HTMLCanvasElement, not on OffscreenCanvas.

Solution

Replaced canvas.toBlob() with canvas.convertToBlob() in the heicTo function. The convertToBlob() method is the correct API for OffscreenCanvas and returns a Promise directly, allowing us to simplify the code by removing the manual Promise wrapper.

Changes

File: src/next/index.js

  • Changed from: canvas.toBlob(callback, type, quality) wrapped in a Promise
  • Changed to: canvas.convertToBlob({ type, quality }) which returns a Promise

Benefits

  1. Fixes the error: Resolves the k.toBlob is not a function error in Next.js projects
  2. Correct API usage: Uses the proper OffscreenCanvas API method
  3. Code simplification: Removes unnecessary Promise wrapper since convertToBlob() already returns a Promise
  4. Better compatibility: Ensures the Next.js version works correctly with web workers and SSR environments

Additional Updates

  • Dependencies: Updated npm dependencies to ensure the build system is up to date
  • Security: Addressed 1 high severity vulnerability found in dependencies during the update process

Testing

  • Rebuilt the package successfully
  • The fix is now available in dist/next/heic-to.js

… and changes to esbuild version 0.25.12, including license additions for several packages.
…vertToBlob for improved performance and error handling.
@hoppergee
Copy link
Owner

Sorry, I missed this. I'll take a look in 2 days.

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

Successfully merging this pull request may close these issues.

2 participants