pbakaus/impeccable · error

Could not extract browser antipattern registry

Error message

Could not extract browser antipattern registry

What it means

Thrown by the browser-detector bundler when the regex `/const ANTIPATTERNS = \[[\s\S]*?\n\];/` does not match the contents of cli/engine/registry/antipatterns.mjs. The bundler extracts that array literal to ship a browser-safe inlined copy; if the array's declaration syntax changes (e.g. renamed, reformatted, or split across files) the extraction breaks.

Source

Thrown at scripts/lib/browser-detector-bundle.js:17

import fs from 'node:fs';
import path from 'node:path';

const BROWSER_DETECTOR_MODULES = [
  'cli/engine/shared/constants.mjs',
  'cli/engine/registry/antipatterns.mjs',
  'cli/engine/shared/color.mjs',
  'cli/engine/shared/fonts.mjs',
  'cli/engine/rules/checks.mjs',
  'cli/engine/browser/injected/index.mjs',
];

function browserSafeModule(root, relPath) {
  let code = fs.readFileSync(path.join(root, relPath), 'utf-8');
  if (relPath === 'cli/engine/registry/antipatterns.mjs') {
    const match = code.match(/const ANTIPATTERNS = \[[\s\S]*?\n\];/);
    if (!match) throw new Error('Could not extract browser antipattern registry');
    code = match[0];
  }
  code = code.replace(/^import[\s\S]*?;\n/gm, '');
  code = code.replace(/^export\s+\{[^}]*\};\n?/gm, '');
  code = code.replace(/^export\s+\{[\s\S]*?^};\n?/gm, '');
  return `// --- ${relPath} ---\n${code.trim()}\n`;
}

export function bundleBrowserDetectorModules(root) {
  return BROWSER_DETECTOR_MODULES
    .map((relPath) => browserSafeModule(root, relPath))
    .join('\n');
}

View on GitHub (pinned to d14711ae3d)

Solutions

  1. Keep the literal declaration `const ANTIPATTERNS = [ ... \n];` intact in cli/engine/registry/antipatterns.mjs so the regex matches.
  2. If you must change the declaration shape, update the regex in scripts/lib/browser-detector-bundle.js to match the new form.
  3. Run `bun run build:browser` after registry edits to fail fast on extraction breakage.

Example fix

// before — renamed constant breaks the extractor
const RULES = [ ... ];

// after — keep the literal name and newline-terminated close
const ANTIPATTERNS = [
  { id: 'side-tab', /* ... */ },
];
Defensive patterns

Strategy: validation

Validate before calling

const code = fs.readFileSync(antipatternsPath, 'utf-8');
if (!/const ANTIPATTERNS = \[[\s\S]*?\n\];/.test(code)) {
  throw new Error('Registry literal shape changed; update the bundler regex.');
}

Type guard

function registryLiteralMatches(code) {
  return /const ANTIPATTERNS = \[[\s\S]*?\n\];/.test(code);
}

Try / catch

try {
  bundleBrowserDetectorModules(root);
} catch (err) {
  if (/extract browser antipattern registry/.test(err.message)) {
    console.error('Registry literal not found; keep `const ANTIPATTERNS = [ ... ];` intact.');
  } else throw err;
}

Prevention

When it happens

Trigger: Renaming the ANTIPATTERNS constant, changing its declaration form (e.g. `export const ANTIPATTERNS=` vs `const ANTIPATTERNS =`), adding a `]` on a non-newline-terminated line, or splitting the array across multiple modules. Fires during `bun run build:browser` / `bun run build`.

Common situations: A refactor moves antipattern definitions into a registry loader that builds the array at runtime; a formatter rewraps the closing `];` onto the same line as content; the file was deleted or moved without updating BROWSER_DETECTOR_MODULES.

Related errors


AI-assisted analysis of pbakaus/impeccable@d14711ae3d (2026-08-13). Data as JSON: /api/errors/3a4ed03d694dfb99. Report an issue: GitHub.