{"id":14845,"library":"qr.js","title":"QR Code Encoding (Legacy)","description":"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.","status":"abandoned","version":"0.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/shtylman/qr.js","tags":["javascript","qrcode","qr"],"install":[{"cmd":"npm install qr.js","lang":"bash","label":"npm"},{"cmd":"yarn add qr.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add qr.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import qr from 'qr.js';","symbol":"qr","correct":"const qr = require('qr.js');"},{"note":"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.","wrong":"import { qrcode } from 'qr.js';\nimport qrcode from 'qr.js';","symbol":"qrcode","correct":"const qrcode = require('qr.js');\nconst cells = qrcode('your data').modules;"}],"quickstart":{"code":"const qr = require('qr.js');\n\n// Data to encode in the QR code\nconst data = 'Hello, Checklist Day!';\n\n// Generate the QR code data structure\nconst qrcode = qr(data);\n\n// Access the QR code cells (modules)\nconst cells = qrcode.modules;\n\nconsole.log(`QR Code for: \"${data}\"`);\nconsole.log(`Version: ${qrcode.typeNumber}`);\nconsole.log(`Error Correction Level: ${qrcode.correctLevel}`);\nconsole.log(`Number of cells (rows): ${cells.length}`);\nconsole.log(`First row of cells: ${cells[0].map(cell => cell ? '██' : '  ').join('')}`);\n\n// Example: Manually printing a small part of the QR code\nfor (let r = 0; r < Math.min(5, cells.length); r++) {\n  let rowOutput = '';\n  for (let c = 0; c < Math.min(10, cells[r].length); c++) {\n    rowOutput += cells[r][c] ? '██' : '  ';\n  }\n  console.log(rowOutput);\n}","lang":"javascript","description":"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."},"warnings":[{"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`).","message":"The 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.","severity":"breaking","affected_versions":">=0.0.0"},{"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).","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"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.","message":"qr.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`.","severity":"deprecated","affected_versions":">=0.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require('qr.js')` in an ES module (`.mjs` file or `type: \"module\"` in `package.json`) environment.","error":"ReferenceError: require is not defined"},{"fix":"Call `qr` as a regular function: `const qrcodeData = qr('your input string');`.","cause":"Incorrectly attempting to instantiate `qr` with `new` (e.g., `new qr(...)`) or calling it with no arguments. The `qr` import directly returns a function.","error":"TypeError: qr is not a function"},{"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.","cause":"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.","error":"Cannot find module 'qr.js'"}],"ecosystem":"npm"}