apify/crawlee · error · Error

Cannot parse Glob pattern '${globTrimmed}': it must be an no

Error message

Cannot parse Glob pattern '${globTrimmed}': it must be an non-empty string

What it means

enqueueLinks() validates each glob pattern with validateGlobPattern, which requires a non-empty (after trimming) string. An empty or whitespace-only glob cannot match any pseudo-URL, so the library throws immediately. Note the message has a typo: it says the value must be 'an non-empty string'.

Source

Thrown at packages/core/src/enqueue_links/shared.ts:148

            if (typeof item === 'string') {
                globObject = { glob: validateGlobPattern(item) };
            } else {
                globObject = { glob: validateGlobPattern(item.glob) };
            }

            updateEnqueueLinksPatternCache(item, globObject);

            return globObject;
        });
}

/**
 * @internal
 */
export function validateGlobPattern(glob: string): string {
    const globTrimmed = glob.trim();
    if (globTrimmed.length === 0)
        throw new Error(`Cannot parse Glob pattern '${globTrimmed}': it must be an non-empty string`);
    return globTrimmed;
}

/**
 * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
 * to check RegExps input and return valid RegExps.
 * @ignore
 */
export function constructRegExpObjectsFromRegExps(regexps: readonly RegExpInput[]): RegExpObject[] {
    return regexps.map((item) => {
        // Get regexp object from cache.
        let regexpObject = enqueueLinksPatternCache.get(item);
        if (regexpObject) return regexpObject;

        if (item instanceof RegExp) {
            regexpObject = { regexp: item };
        } else {
            regexpObject = { regexp: item.regexp };

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Filter out empty/whitespace entries before passing globs
  2. Validate the env/config value has a default fallback
  3. Ensure patterns actually match target URLs (also check syntax)
  4. Write the glob per pseudo-URL syntax, e.g. 'https://example.com/(.*)'

Example fix

// before
await enqueueLinks({ globs: (process.env.GLOB ?? '').split(',') });
// after
await enqueueLinks({ globs: (process.env.GLOB ?? '').split(',').map((g) => g.trim()).filter(Boolean) });
Defensive patterns

Strategy: validation

Validate before calling

const globs = rawGlobs.map((g) => g.trim()).filter((g) => g.length > 0);
if (globs.length === 0) throw new Error('at least one non-empty glob required');

Type guard

const isValidGlob = (g: string): boolean => typeof g === 'string' && g.trim().length > 0;

Prevention

When it happens

Trigger: Passing globs: [''] or [' '] (whitespace-only) to enqueueLinks() or enqueueLinksByClickingElements(); building globs from env/config values that resolve to empty strings.

Common situations: process.env.SITE_GLOB unset yielding ''; config files with placeholder empty entries; string-splitting producing empty elements (e.g. 'a,,b'.split(',')).

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/ba267bc030fc041b. Report an issue: GitHub.