undecaf / zbar-wasm Goto Github PK
View Code? Open in Web Editor NEWA WebAssembly build of the ZBar Bar Code Reader
License: GNU Lesser General Public License v2.1
A WebAssembly build of the ZBar Bar Code Reader
License: GNU Lesser General Public License v2.1
Can you add support for the datamatrix code?
Thank you!
I develop capacitor-community/barcode-scanner and want to make it support off-line, so zbar.wasm needs to be included.
I successfully included it in a dist of this module:
plugins: [
copy({
targets: [
{ src: 'node_modules/@undecaf/zbar-wasm/dist/zbar.wasm', dest: 'dist' },
]
})
],
But when I use barcode-scanner in my project (npm i "@capacitor-community/barcode-scanner@../barcode-scanner"
for local development) and build it, resulting dist does not include zbar.wasm file.
I checked example-bundled, but this seems not intended for use in the module project (and also it is for old rollup 2).
Or it is really necessary to ask module's users to bundle zbar.wasm themself? How to make zbar-wasm to require it correctly then?
Thank you for your help.
Describe the bug
On Ipad safari the webassembly script fails to compile due to the following error:
failed to asynchronously prepare wasm: CompileError: WebAssembly.Module doesn't parse at byte 1227: invalid opcode 192, in function at index 28
To Reproduce
Opening the example on an ipad and uploading an image file of a barcode https://undecaf.github.io/zbar-wasm/example/ will result in "Source not ready" with the specified error above.
Or else the environment in which the behavior occurs needs to be specified:
https://output.jsbin.com/nidonin
Please try my live sample based on zbar.wasm, which will detecting QR or other supported code types continuously. Just open it on your iPhone or Android phone then point & shoot. It outperforms other pure JavaScript QR detection libraries.
But sometime my live sample stops to detect from new video feed, even once it recognized correctly just seconds ago. I figured out one pattern to reproduce this bug:
From https://github.com/mebjas/html5-qrcode, I printed out many different types of QR code and Barcode for testing.
Nodejs 18 breaks emscripten
Fix: bump emscripten to the latest version.
e.g. this
Hello, I am trying different images with the codepen demo site, but have a problem.
Files of very big images (40-50 MP) are returning with no results '[ ]', in the first try.
Same image, second attempt from same file, all is well, all qrcodes are correctly identified. If I resize down to something around 2000px width, instant result comes, no problems even in the first attempt with that file.
What might be causing this ?
The image is confidential, so it should be removed
'Error: Corrupted zip: missing 48 bytes.\n at ZipEntries.readEndOfCentral (D:\codebase\iona\onboarding-dbmodel\node_modules\jszip\lib\zipEntries.js:243:19)\n at ZipEntries.load (D:\codebase\iona\onboarding-dbmodel\node_modules\jszip\lib\zipEntries.js:255:14)\n at D:\codebase\iona\onboarding-dbmodel\node_modules\jszip\lib\load.js:48:24'
I get the following error with the latest version:
ERROR in ../../node_modules/@undecaf/zbar-wasm/dist/main.js 15:653-669
Module not found: Error: Can't resolve 'module' in '/myprj/node_modules/@undecaf/zbar-wasm/dist'
resolve 'module' in '/myprj/node_modules/@undecaf/zbar-wasm/dist'
Parsed request is a module
using description file: /myprj/node_modules/@undecaf/zbar-wasm/package.json (relative path: ./dist)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in /myprj/packages/sub-project/node_modules
single file module
using description file: /myprj/packages/sub-project/package.json (relative path: ./node_modules/module)
no extension
Field 'browser' doesn't contain a valid alias configuration
/myprj/packages/sub-project/node_modules/module doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/myprj/packages/sub-project/node_modules/module.js doesn't exist
/myprj/packages/sub-project/node_modules/module doesn't exist
looking for modules in /myprj/node_modules
single file module
using description file: /myprj/package.json (relative path: ./node_modules/module)
no extension
Field 'browser' doesn't contain a valid alias configuration
/myprj/node_modules/module doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/myprj/node_modules/module.js doesn't exist
/myprj/node_modules/module doesn't exist
@ ./out/file.js 1:0-51 14:22-35 21:22-35
webpack 5.88.2 compiled with 1 error in 1608 ms
Describe the bug
Hello! I fail to build when trying to use this library within the Next.JS app directory router. I tried several methods like dynamic import, but none worked. Also, it works with npm run dev
.
Thank you.
Next.js 14.0.2
To Reproduce
using node v20.8.0 (npm v10.1.0)
npx create-next-app@latest
** default settings ***
overwrite
src/app/page.tsx
as
'use client'
import { scanImageData } from "@undecaf/zbar-wasm";
export default function Home() {
scanImageData(new ImageData(1, 1));
return (
<></>
)
}
overwrite
next.config.ts
as
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@undecaf/zbar-wasm'],
}
module.exports = nextConfig
and
npm run build
error message
Failed to compile.
static/media/index.33c29f02.mjs from Terser
x 'import.meta' cannot be used outside of module code.
,-[24:1]
24 | });
25 | }
26 | "function" == typeof SuppressedError && SuppressedError;
27 | var e, r = (e = import.meta.url, async function() {
: ^^^^^^^^^^^
28 | let t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
29 | var r, n, i = t;
30 | i.ready = new Promise((t, e)=>{
`----
x 'import.meta' cannot be used outside of module code.
,-[33:1]
33 | var o, s, a, c = Object.assign({}, i), _ = "object" == "object", u = "function" == typeof importScripts, A = "object" == typeof process && "object" == typeof process.versions && "string" == typeof process.versions.node, f = "";
34 | if (A) {
35 | const { createRequire: t } = await Promise.resolve().then(()=>g);
36 | var h = t(import.meta.url), l = h("fs"), R = h("path");
: ^^^^^^^^^^^
37 | f = u ? R.dirname(f) + "/" : h("url").fileURLToPath(new URL("./", import.meta.url)), o = (t, e)=>(t = U(t) ? new URL(t) : R.normalize(t), l.readFileSync(t, e ? void 0 : "utf8")), a = (t)=>{
38 | var e = o(t, !0);
39 | return e.buffer || (e = new Uint8Array(e)), e;
`----
x 'import.meta' cannot be used outside of module code.
,-[34:1]
34 | if (A) {
35 | const { createRequire: t } = await Promise.resolve().then(()=>g);
36 | var h = t(import.meta.url), l = h("fs"), R = h("path");
37 | f = u ? R.dirname(f) + "/" : h("url").fileURLToPath(new URL("./", import.meta.url)), o = (t, e)=>(t = U(t) ? new URL(t) : R.normalize(t), l.readFileSync(t, e ? void 0 : "utf8")), a = (t)=>{
: ^^^^^^^^^^^
38 | var e = o(t, !0);
39 | return e.buffer || (e = new Uint8Array(e)), e;
40 | }, s = function(t, e, r) {
`----
x 'import.meta' cannot be used outside of module code.
,-[98:1]
98 | B("failed to asynchronously prepare wasm: " + t), P(t);
99 | });
100 | }
101 | i.locateFile ? F(T = "zbar.wasm") || (O = T, T = i.locateFile ? i.locateFile(O, f) : f + O) : T = new URL("zbar.wasm", import.meta.url).href;
: ^^^^^^^^^^^
102 | var L, M = (t)=>{
103 | for(; t.length > 0;)t.shift()(i);
104 | }, x = (t)=>{
`----
x 'import', and 'export' cannot be used outside of module code
,-[385:1]
385 | }, Symbol.toStringTag, {
386 | value: "Module"
387 | }));
388 | export { a as ZBarConfigType, l as ZBarImage, c as ZBarOrientation, R as ZBarScanner, h as ZBarSymbol, s as ZBarSymbolType, d as getDefaultScanner, o as getInstance, y as scanGrayBuffer, E as scanImageData, B as scanRGBABuffer }; //# sourceMappingURL=index.mjs.map
: ^^^^^^
`----
Caused by:
0: failed to parse input file
1: Syntax Error
Error:
x 'import.meta' cannot be used outside of module code.
,-[24:1]
24 | });
25 | }
26 | "function" == typeof SuppressedError && SuppressedError;
27 | var e, r = (e = import.meta.url, async function() {
: ^^^^^^^^^^^
28 | let t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
29 | var r, n, i = t;
30 | i.ready = new Promise((t, e)=>{
`----
x 'import.meta' cannot be used outside of module code.
,-[33:1]
33 | var o, s, a, c = Object.assign({}, i), _ = "object" == "object", u = "function" == typeof importScripts, A = "object" == typeof process && "object" == typeof process.versions && "string" == typeof process.versions.node, f = "";
34 | if (A) {
35 | const { createRequire: t } = await Promise.resolve().then(()=>g);
36 | var h = t(import.meta.url), l = h("fs"), R = h("path");
: ^^^^^^^^^^^
37 | f = u ? R.dirname(f) + "/" : h("url").fileURLToPath(new URL("./", import.meta.url)), o = (t, e)=>(t = U(t) ? new URL(t) : R.normalize(t), l.readFileSync(t, e ? void 0 : "utf8")), a = (t)=>{
38 | var e = o(t, !0);
39 | return e.buffer || (e = new Uint8Array(e)), e;
`----
x 'import.meta' cannot be used outside of module code.
,-[34:1]
34 | if (A) {
35 | const { createRequire: t } = await Promise.resolve().then(()=>g);
36 | var h = t(import.meta.url), l = h("fs"), R = h("path");
37 | f = u ? R.dirname(f) + "/" : h("url").fileURLToPath(new URL("./", import.meta.url)), o = (t, e)=>(t = U(t) ? new URL(t) : R.normalize(t), l.readFileSync(t, e ? void 0 : "utf8")), a = (t)=>{
: ^^^^^^^^^^^
38 | var e = o(t, !0);
39 | return e.buffer || (e = new Uint8Array(e)), e;
40 | }, s = function(t, e, r) {
`----
x 'import.meta' cannot be used outside of module code.
,-[98:1]
98 | B("failed to asynchronously prepare wasm: " + t), P(t);
99 | });
100 | }
101 | i.locateFile ? F(T = "zbar.wasm") || (O = T, T = i.locateFile ? i.locateFile(O, f) : f + O) : T = new URL("zbar.wasm", import.meta.url).href;
: ^^^^^^^^^^^
102 | var L, M = (t)=>{
103 | for(; t.length > 0;)t.shift()(i);
104 | }, x = (t)=>{
`----
x 'import', and 'export' cannot be used outside of module code
,-[385:1]
385 | }, Symbol.toStringTag, {
386 | value: "Module"
387 | }));
388 | export { a as ZBarConfigType, l as ZBarImage, c as ZBarOrientation, R as ZBarScanner, h as ZBarSymbol, s as ZBarSymbolType, d as getDefaultScanner, o as getInstance, y as scanGrayBuffer, E as scanImageData, B as scanRGBABuffer }; //# sourceMappingURL=index.mjs.map
: ^^^^^^
`----
Caused by:
0: failed to parse input file
1: Syntax Error
> Build failed because of webpack errors
Creating an optimized production build .%
Or else the environment in which the behavior occurs needs to be specified:
package.json
content{
"name": "test-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@undecaf/zbar-wasm": "^0.10.1",
"next": "14.0.2",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.0.2",
"postcss": "^8",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
}
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
iwhen i call import { scanImageData } from '@undecaf/zbar-wasm'; and use return scanImageData(imageData)
.then(symbols => { ...
I show this error, how can fixe that please
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Not allowed to load local resource: file:///D://node_modules/@undecaf/zbar-wasm/dist/zbar.wasm
Aborted([object ProgressEvent]). Build with -sASSERTIONS for more info.
RuntimeError: Aborted([object ProgressEvent]). Build with -sASSERTIONS for more info.
Hello! I'm trying to add this library to my project that's using next.js
But I get this error and it doesn't build
Here's a reproducible example:
I am encountering the following error trying to integrate zbar-wasm in a Quasar + Vite project:
main.js:15 Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
at n (main.js:15:3357)
at main.js:15:7714
at Generator.next (<anonymous>)
at main.js:15:283
at new Promise (<anonymous>)
at t (main.js:15:28)
at main.js:15:7667
Describe the bug
When using the example on IOS Safari Iphone 12 initially the default hi-res rear camera is used. Leaving the web scanner on in background causes a different camera (fisheye) to be selected. Making scanning nearly impossible.
To Reproduce
Visit demo through Github
Expected behavior
Expected behaviour would be to have the same camera active after returning from background/sleep.
Screenshots
Initial Cam | Cam after BG |
---|---|
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.