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

loading zbar-wasm as ES module fails in Node #9

Closed
da1z opened this issue Aug 4, 2023 · 2 comments
Closed

loading zbar-wasm as ES module fails in Node #9

da1z opened this issue Aug 4, 2023 · 2 comments

Comments

@da1z
Copy link

da1z commented Aug 4, 2023

I am using it like this:

import { createCanvas, loadImage } from 'canvas';
import { scanImageData } from '@undecaf/zbar-wasm';

const getImageData = async (src) => {
  const img = await loadImage(src);
  const canvas = createCanvas(img.width, img.height);
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.getImageData(0, 0, img.width, img.height);
};

const url = 'src/IMG_3361.jpg';
const main = async () => {
  const img = await getImageData(url);
  const res = await scanImageData(img);
  console.log(res[0]?.typeName);
  console.log(res[0]);
  console.log(res[0]?.decode());
};

main();

and getting

TypeError: t is not a function at n (file:///Users/Projects/scna/node_modules/@undecaf/zbar-wasm/dist/main.js:15:706)

@undecaf
Copy link
Owner

undecaf commented Aug 4, 2023

While I am looking into this, you could try to replace

import { scanImageData } from '@undecaf/zbar-wasm';

with

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { scanImageData } = require('@undecaf/zbar-wasm');

as a workaround. This is equivalent to what the missing function t should do.

@undecaf undecaf closed this as completed in bbddd7b Aug 4, 2023
@undecaf undecaf changed the title getting t is not a function loading zbar-wasm as ES module fails in Node Aug 4, 2023
@undecaf
Copy link
Owner

undecaf commented Aug 4, 2023

@da1z : Should be fixed in version 0.9.16, please feel free to re-open.

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

2 participants