Registry / serialization / qr.js
library0.0.0jsnpmunverified

qr.js is a minimalist JavaScript library designed for encoding QR codes directly within the browser or Node.js environments. Published as version 0.0.0, the package has been unmaintained since its last update in November 2015. It is notable for its pure JavaScript implementation with no external dependencies, repackaging work from a Japanese qrcode library. Despite its initial purpose and wide adoption in older projects, its lack of maintenance and critical security issues, including a repository hijacking incident, make it unsuitable for new development. Developers are strongly advised to consider modern, actively maintained alternatives for QR code generation to ensure security and compatibility.

npm install qr.js
INSTALL
IMPORT
SIG · QR.JS
Q
qr.js
serializationjavascriptv0.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

qr
✓ const qr = require('qr.js');
✗ import qr from 'qr.js';
This package is CommonJS-only. There is no official ESM export, and attempting to import it with `import` will likely result in an error or an undefined module.
qrcode
✓ const qrcode = require('qr.js'); const cells = qrcode('your data').modules;
✗ import { qrcode } from 'qr.js'; import qrcode from 'qr.js';
The default export is a function that, when called with a string, returns an object containing QR code data, including the 'modules' array representing the cells.

This quickstart demonstrates how to use `qr.js` to encode a string into a QR code data structure and inspect its underlying cell matrix (`modules`). It then prints a small portion of the QR code's visual representation using block characters.

const qr = require('qr.js'); // Data to encode in the QR code const data = 'Hello, Checklist Day!'; // Generate the QR code data structure const qrcode = qr(data); // Access the QR code cells (modules) const cells = qrcode.modules; console.log(`QR Code for: "${data}"`); console.log(`Version: ${qrcode.typeNumber}`); console.log(`Error Correction Level: ${qrcode.correctLevel}`); console.log(`Number of cells (rows): ${cells.length}`); console.log(`First row of cells: ${cells[0].map(cell => cell ? '██' : ' ').join('')}`); // Example: Manually printing a small part of the QR code for (let r = 0; r < Math.min(5, cells.length); r++) { let rowOutput = ''; for (let c = 0; c < Math.min(10, cells[r].length); c++) { rowOutput += cells[r][c] ? '██' : ' '; } console.log(rowOutput); }
Debug
Known issues
breakingThe original GitHub repository (shtylman/qr.js) was subject to a hijacking incident in late 2021. If your project directly linked to this specific GitHub URL as a dependency (e.g., via `git+https://github.com/shtylman/qr.js`), your builds would have failed or potentially pulled malicious code at the time.
fix
Immediately cease direct GitHub URL dependencies. Replace `qr.js` with a modern, actively maintained QR code library from npm (e.g., `qrcode` or `qrcode.react`).
affects: >=0.0.0
gotchaThe package is published as version 0.0.0 and has not been updated since November 2015. This indicates a complete lack of maintenance, no semantic versioning, and potential incompatibility with modern JavaScript environments or security practices.
fix
Avoid using `qr.js` for new projects. Migrate existing projects to a well-maintained alternative. Consider `qrcode` (for Node.js/browser, supports various output formats) or `qrcode.react` (for React applications).
affects: >=0.0.0
deprecatedqr.js strictly uses CommonJS `require()` syntax. It does not provide native ESM exports, which can lead to compatibility issues in modern JavaScript module environments that primarily use `import`/`export`.
fix
If you must use this package in an ESM context (not recommended), you might need to rely on bundlers or Node.js's CJS-ESM interop features, such as `import * as qr from 'qr.js';`, but this is not guaranteed to work seamlessly or consistently. The best fix is to use an ESM-compatible QR code library.
affects: >=0.0.0
gotchaThis library only provides the raw QR code data (a 2D array of boolean cells) and does not include rendering capabilities (e.g., to canvas, SVG, or image files) out of the box. You would need to implement rendering logic yourself.
fix
If you need a library that directly renders QR codes to visual formats (e.g., canvas, SVG, PNG), consider alternatives like `qrcode` (npm package) which offers `toCanvas`, `toDataURL`, `toFile` methods, or `qrcode.react` for React environments.
affects: >=0.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require('qr.js')` in an ES module (`.mjs` file or `type: "module"` in `package.json`) environment.
fix
This package is CommonJS only. Either convert your project to use CommonJS (not recommended for new projects), or use a bundler that handles CJS-ESM interop. The recommended fix is to replace `qr.js` with a modern QR code library that supports ESM.
TypeError: qr is not a function
Incorrectly attempting to instantiate `qr` with `new` (e.g., `new qr(...)`) or calling it with no arguments. The `qr` import directly returns a function.
fix
Call `qr` as a regular function: `const qrcodeData = qr('your input string');`.
Cannot find module 'qr.js'
This error could stem from incorrect installation, a typo in the package name, or, historically, issues related to the original GitHub repository's hijacking if you were relying on a direct git URL.
fix
Ensure `qr.js` is correctly installed via `npm install qr.js`. If you were linking to a GitHub URL, update your dependencies to use the npm package or, preferably, switch to a different, maintained QR code library.
Upgrade
Version history
0.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
qr.js — npm install qr.js · libregistry