{"id":14847,"library":"qrcode-reader","title":"QR Code Reader","description":"qrcode-reader is a JavaScript library for decoding QR codes from various image data sources. It functions as a maintained fork of Lazarsoft's popular jsqrcode project, providing QR code reading capabilities in both Node.js environments and HTML5-enabled browsers. The package is currently at version 1.0.4, and while a formal release cadence isn't specified, its \"maintained fork\" status indicates ongoing support and bug fixes, though updates may not be frequent. A key characteristic is its pure JavaScript implementation, avoiding native dependencies that can complicate installation, particularly for cross-platform deployment. For Node.js usage, it necessitates an external image parsing library such as Jimp or image-parser to handle raw image buffers and convert them into the specific bitmap format expected by the decoder. Conversely, in browser contexts, it integrates directly with the native Image global object or canvas ImageData objects, simplifying client-side implementation. It utilizes a callback-based API for asynchronous operations.","status":"active","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/edi9999/jsqrcode","tags":["javascript"],"install":[{"cmd":"npm install qrcode-reader","lang":"bash","label":"npm"},{"cmd":"yarn add qrcode-reader","lang":"bash","label":"yarn"},{"cmd":"pnpm add qrcode-reader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing image data from buffers or files in Node.js environments. Recommended for its pure JavaScript nature.","package":"jimp","optional":true},{"reason":"Alternative for parsing image data in Node.js, but introduces native dependencies (lwip/graphicsmagick) for image processing.","package":"image-parser","optional":true}],"imports":[{"note":"This package primarily uses CommonJS `require()` syntax and does not provide ESM exports directly. This is the correct way to import it in Node.js.","wrong":"import QrCode from 'qrcode-reader';","symbol":"QrCode","correct":"const QrCode = require('qrcode-reader');"},{"note":"For browser environments, the library is typically consumed by including the `dist/index.js` file via a `<script>` tag. This exposes the `QrCode` constructor as a global variable; no direct import statement is used in this context.","symbol":"QrCode (Browser Global)","correct":"<script src=\"dist/index.js\"></script>\n// Then access via global QrCode variable"}],"quickstart":{"code":"const fs = require('fs');\nconst Jimp = require('jimp');\nconst QrCode = require('qrcode-reader');\n\n// IMPORTANT: For this code to run, you need a QR code image file (e.g., 'qrcode.png')\n// in the same directory as your script, or update 'imagePath' to point to one.\n// You can generate a simple 'Hello World' QR code using an online generator or a library.\nconst imagePath = './qrcode.png'; \n\ntry {\n  const buffer = fs.readFileSync(imagePath);\n\n  Jimp.read(buffer, function(err, image) {\n      if (err) {\n          console.error(\"Error reading image with Jimp:\", err);\n          return;\n      }\n      const qr = new QrCode();\n      qr.callback = function(err, value) {\n          if (err) {\n              console.error(\"QR Code decoding error:\", err);\n              return;\n          }\n          console.log(\"QR Code result:\", value.result);\n          console.log(\"Decoded value details:\", value);\n      };\n      // The 'image.bitmap' object from Jimp provides { width, height, data } \n      // in a format expected by qrcode-reader.\n      qr.decode(image.bitmap);\n  });\n} catch (readErr) {\n  console.error(`Failed to read QR code image at ${imagePath}. Please ensure the file exists and is accessible.\\nIf you don't have one, create a simple 'qrcode.png' in the same directory as this script.`);\n}","lang":"javascript","description":"Demonstrates how to read and decode a QR code from an image file in a Node.js environment, utilizing the Jimp library for image parsing."},"warnings":[{"fix":"Install `jimp` (`npm install --save jimp`) or `image-parser` and use it to read the image data, then pass the processed bitmap (e.g., `image.bitmap` from Jimp) to `qr.decode()`.","message":"In Node.js environments, `qrcode-reader` requires a separate image processing library (e.g., `jimp` or `image-parser`) to convert image files or buffers into a compatible bitmap format before decoding. The library itself does not handle raw image file parsing.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap the `qr.decode` call within a Promise manually if a Promise-based API is desired, or adhere to the callback convention.","message":"The API is entirely callback-based, using a `qr.callback = function(error, result) { ... }` pattern. It does not return Promises, which is a common pattern in modern asynchronous JavaScript.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `jimp` for Node.js image parsing if you want to avoid native dependencies, as it is a pure JavaScript solution. If `image-parser` is necessary, be prepared to resolve system-level dependencies for `lwip` or `graphicsmagick`.","message":"Using `image-parser` as an alternative to `jimp` in Node.js introduces native dependencies (`lwip` or `graphicsmagick`), which can lead to complex installation issues, especially across different operating systems or environments.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the external image parser (like Jimp) correctly loads the image and provides the bitmap data in the expected `{width, height, data}` format. Double-check the image path/buffer for corruption or invalid format.","cause":"The `qr.decode()` method was called with an incorrect or incomplete image bitmap object (e.g., missing `width`, `height`, or `data` properties), typically when `jimp` or `image-parser` did not properly process the image data.","error":"TypeError: Cannot read properties of undefined (reading 'width')"},{"fix":"Verify the absolute or relative path to the image file. Ensure the Node.js process has read permissions for the file, and that the file actually exists at the specified location.","cause":"The image file specified could not be found or accessed by the Node.js process at the given path.","error":"Error: ENOENT: no such file or directory, open './qrcode.png'"}],"ecosystem":"npm"}