denoland/deno · error · TypeError

pattern is too long

Error message

pattern is too long

What it means

minimatch caps pattern length at 65536 characters (MAX_PATTERN_LENGTH = 1024 * 64) to prevent pathological parsing work. A longer pattern throws a TypeError ('pattern is too long') before any matching happens, after the string-type check passes.

Source

Thrown at ext/node/polyfills/deps/minimatch.js:257

        return expansions;
      }
    }
  }
});

// node_modules/.deno/minimatch@10.2.5/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js
var require_assert_valid_pattern = __commonJS({
  "node_modules/.deno/minimatch@10.2.5/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js"(exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.assertValidPattern = void 0;
    var MAX_PATTERN_LENGTH = 1024 * 64;
    var assertValidPattern = (pattern) => {
      if (typeof pattern !== "string") {
        throw new TypeError("invalid pattern");
      }
      if (pattern.length > MAX_PATTERN_LENGTH) {
        throw new TypeError("pattern is too long");
      }
    };
    exports.assertValidPattern = assertValidPattern;
  }
});

// node_modules/.deno/minimatch@10.2.5/node_modules/minimatch/dist/commonjs/brace-expressions.js
var require_brace_expressions = __commonJS({
  "node_modules/.deno/minimatch@10.2.5/node_modules/minimatch/dist/commonjs/brace-expressions.js"(exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.parseClass = void 0;
    var posixClasses = {
      "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
      "[:alpha:]": ["\\p{L}\\p{Nl}", true],
      "[:ascii:]": ["\\x00-\\x7f", false],
      "[:blank:]": ["\\p{Zs}\\t", true],
      "[:cntrl:]": ["\\p{Cc}", true],

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Split into many small patterns and compile each: patterns.map(p => new minimatch.Minimatch(p))
  2. Prune before joining — deduplicate and drop dead entries so the pattern stays hand-sized
  3. For very large alternative sets, use a plain regex or prefix matching instead of one mega-glob

Example fix

// before
const ok = files.every((f) => minimatch(f, giantJoinedPattern));
// after
const matchers = patterns.map((p) => new minimatch.Minimatch(p));
const ok = files.every((f) => matchers.some((m) => m.match(f)));
Defensive patterns

Strategy: validation

Validate before calling

const MAX_PATTERN = 64 * 1024; // minimatch's MAX_PATTERN_LENGTH
for (const p of patterns) {
  if (typeof p === "string" && p.length > MAX_PATTERN) {
    throw new RangeError("glob pattern exceeds 65536 chars; split it into multiple patterns");
  }
}

Type guard

const isShortPattern = (p) => typeof p === "string" && p.length <= 64 * 1024;

Try / catch

try { ok = minimatch(path, pattern); }
catch (e) {
  if (e instanceof TypeError && e.message === "pattern is too long") {
    ok = splitPattern(pattern).some((p) => minimatch(path, p));
  } else throw e;
}

Prevention

When it happens

Trigger: One giant pattern string built from thousands of OR-joined alternatives; huge brace expansions ({a,b,c,...}); concatenating an entire exclusion list into a single pattern; unbounded user input appended to a glob.

Common situations: Build tools generating one pattern per source file and joining them; ignore-lists collapsed into one string; script- or model-generated patterns that enumerate vast alternative sets.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/341de14e2a719879. Report an issue: GitHub.