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
- Default missing patterns: pattern ?? "**/*" or skip the call when absent
- If you have multiple patterns, loop over them — never pass an array or other type where one string belongs
- 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
- Default optional glob config to '**/*' or skip the call when absent
- Schema-validate config that contains globs
- Never forward a RegExp where a glob string is expected
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
- pattern is too long
- Expected the second argument to assertSnapshot() to be an op
- Snapshot serializer must return a string
- Return value from serve handler must be a response or a prom
- ERR_INVALID_ARG_TYPE
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/700ae4ba58e45190.
Report an issue: GitHub.