Dynamsoft / barcode-reader-javascript

Dynamsoft Barcode Reader JavaScript SDK for package managers. PDF417, QR Code, DataMatrix, MaxiCode and more are supported.
https://www.dynamsoft.com/barcode-reader/sdk-javascript/
Other
170 stars 110 forks source link

Node.js: The browser doesn't support Webassembly. #34

Closed ahmedEnosis closed 5 years ago

ahmedEnosis commented 5 years ago

I have tried to install the dynamsoft-javascript-barcode package using npm and execute the example code provided here. It was throwing me the following error saying Webassembly is not supported in the browser(As node doesn't naively support webassembly). I've also found this instruction to wrap the sdk for linux environment. But, I was wondering if there is a way where would could use the bar-code reader right of the bat skipping the manual build procedure.

Error:

Error: 'Constructor BarcodeReader(productKeys)': The browser doesn't support Webassembly.
    at Error (native)
    at then.a._loadWasmStatus (\path\to\project\dbr\dbr.min.js:63:430)
    at \path\to\project\dbr\dbr.min.js:63:101
    at Timeout._onTimeout (\path\to\project\dbr\dbr.min.js:15:423)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
yushulx commented 5 years ago

@ahmedEnosis The dynamsoft-javascript-barcode is based on WebAssembly, which means you can use it on any platforms including Windows, Linux, macOS, and Raspberry Pi. Do you have an image file named sample.png in your project folder?

Annotation 2019-09-10 070659

We have provided a test image under node_modules\dynamsoft-javascript-barcode\samples\sample.png. You can use it for testing Node.js code.

reader.decode('sample.png')

In addition, please get a trial license and update the following line in your code:

dbr.BarcodeReader.productKeys = 'LICENSE-KEY';

Here are my results:

Annotation 2019-09-10 071020

yushulx commented 5 years ago

@ahmedEnosis Note: the link https://www.codepool.biz/linux-barcode-sdk-node-javascript.html shares how to wrap the C++ barcode SDK (which is platform-dependent) for Node.js. It's totally different from dynamsoft-javascript-barcode.

ahmedEnosis commented 5 years ago

@yushulx, thank you for your help. It turns out I was following the proper procedure in the code but, my node version that I was using (6.2.2) does not play well with webassembly. So, I changed node version to 10.15.3 and everything seems to be working just fine.