denoland/deno · error · TypeError

invalid pattern

Error message

invalid pattern

What it means

Deno bundles minimatch for glob matching inside its Node polyfills; assertValidPattern requires every pattern to be a string and throws a TypeError ('invalid pattern') before any parsing or matching starts. This mirrors upstream minimatch@10 behavior.

Source

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

            }
          }
        }
        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],

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Default missing patterns: pattern ?? "**/*" or skip the call when absent
  2. If you have multiple patterns, loop over them — never pass an array or other type where one string belongs
  3. Stringify only genuinely textual values at the boundary, and reject the rest

Example fix

// before
minimatch("src/a.ts", cfg.include);
// after
minimatch("src/a.ts", cfg.include ?? "**/*");
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof pattern !== "string" || pattern === "") {
  throw new TypeError(`glob pattern must be a non-empty string, got ${typeof pattern}`);
}

Type guard

const isGlobPattern = (p) => typeof p === "string" && p.length > 0;

Try / catch

try { return minimatch(path, pattern); }
catch (e) {
  if (e instanceof TypeError && e.message === "invalid pattern") {
    return false; // no usable pattern -> no match
  } else throw e;
}

Prevention

When it happens

Trigger: Calling a glob/match API with a pattern variable that is undefined, null, a number, or a RegExp; forwarding values from JSON config or URL params into the pattern position without type checking.

Common situations: Optional config keys (include/exclude globs) that are absent in some environments; API boundaries where callers send non-strings; mixing RegExp (accepted by some matchers) with glob strings (required by minimatch).

Related errors


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