{"record":{"id":"1cb4d1d85718a772","repo":"withastro/astro","slug":"glob-patterns-cannot-start-with-set-the-base","errorCode":null,"errorMessage":"Glob patterns cannot start with `/`. Set the `base` option to a parent directory or use a relative path instead.","messagePattern":"Glob patterns cannot start with `/`\\. Set the `base` option to a parent directory or use a relative path instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/loaders/glob.ts","lineNumber":91,"sourceCode":"\t}\n\treturn pattern.startsWith(prefix);\n}\n\nexport const secretLegacyFlag = Symbol('astro.legacy-glob');\n\n/**\n * Loads multiple entries, using a glob pattern to match files.\n * @param pattern A glob pattern to match files, relative to the content directory.\n */\n\nexport function glob(globOptions: GlobOptions & { [secretLegacyFlag]?: boolean }): Loader {\n\tif (checkPrefix(globOptions.pattern, '../')) {\n\t\tthrow new Error(\n\t\t\t'Glob patterns cannot start with `../`. Set the `base` option to a parent directory instead.',\n\t\t);\n\t}\n\tif (checkPrefix(globOptions.pattern, '/')) {\n\t\tthrow new Error(\n\t\t\t'Glob patterns cannot start with `/`. Set the `base` option to a parent directory or use a relative path instead.',\n\t\t);\n\t}\n\n\tconst isLegacy = !!globOptions[secretLegacyFlag];\n\tconst userGenerateId =\n\t\tglobOptions?.generateId ?? ((opts: GenerateIdOptions) => generateIdDefault(opts, isLegacy));\n\t// Coerce to string so numeric ids from YAML don't cause Set strict-equality mismatches\n\t// against string store keys in the untouched-entries cleanup. See #17624.\n\tconst generateId = (opts: GenerateIdOptions) => String(userGenerateId(opts));\n\n\tconst fileToIdMap = new Map<string, string>();\n\n\treturn {\n\t\tname: 'glob-loader',\n\t\tload: async ({\n\t\t\tconfig,\n\t\t\tcollection,","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/content/loaders/glob.ts#L73-L109","documentation":"Thrown as a plain Error (no AstroError code) by the glob() loader constructor when any pattern starts with '/'. Absolute-style patterns are disallowed because they are interpreted relative to the filesystem root, not the project; the API requires either a relative pattern or an explicit base.","triggerScenarios":"Calling glob({ pattern: '/content/*.md' }) or glob({ pattern: ['/posts/*.md'] }) — any element beginning with '/'.","commonSituations":"Mistakingly treating the pattern as project-root-relative (common coming from Next.js or other frameworks); copying a Unix path into the pattern; auto-generated patterns that prefix '/'.","solutions":["Drop the leading slash to make the pattern relative: glob({ pattern: 'content/*.md' }).","If you need a specific root, set base to that directory and keep the pattern relative.","If you genuinely need an absolute location, pass an absolute file URL via base and a relative pattern."],"exampleFix":"// before\nglob({ pattern: '/content/posts/*.md' })\n// after\nglob({ pattern: 'content/posts/*.md' })","handlingStrategy":"validation","validationCode":"function normalizeGlobPattern(pattern: string | string[]) {\n  const arr = Array.isArray(pattern) ? pattern : [pattern];\n  for (const p of arr) {\n    if (p.startsWith('/')) throw new Error('Pattern must be relative; drop leading slash');\n  }\n}","typeGuard":"const isAbsolutePattern = (p: string) => p.startsWith('/');","tryCatchPattern":null,"preventionTips":["Use relative patterns (no leading slash).","Set base explicitly when you need a specific root.","Lint content configs for leading-slash patterns."],"tags":["content-collections","loader","glob-loader","path","config-mistake"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}