{"record":{"id":"b63660f3f153195f","repo":"gatsbyjs/gatsby","slug":"pagecreator-to-query-node-gatsbypath-the-filep","errorCode":null,"errorMessage":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must be an absolute path, starting with a /\nPlease change this to: \"/${filePath}\"","messagePattern":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must be an absolute path, starting with a /\nPlease change this to: \"/(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-page-creator/src/validate-path-query.ts","lineNumber":10,"sourceCode":"import _ from \"lodash\"\nimport systemPath from \"path\"\n\nexport function validatePathQuery(\n  filePath: string,\n  extensions: Array<string>\n): void {\n  // Paths must start with /\n  if (filePath.startsWith(`/`) !== true) {\n    throw new Error(`PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must be an absolute path, starting with a /\nPlease change this to: \"/${filePath}\"`)\n  }\n\n  // Paths must not include file extension\n  if (/\\.[a-z]+$/i.test(filePath)) {\n    throw new Error(`PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit the file extension\nPlease change ${filePath} to \"${filePath.replace(/\\.[a-z]+$/i, ``)}\"`)\n  }\n\n  // Paths must not utilize src/pages\n  if (filePath.includes(`src/pages`)) {\n    throw new Error(`PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit the src/pages prefix.\nPlease change this to: \"${filePath.replace(/\\/?src\\/pages\\//, ``)}\"`)\n  }\n\n  // Paths must not include index\n  if (/index$/.test(filePath)) {\n    throw new Error(","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-page-creator/src/validate-path-query.ts#L1-L28","documentation":"validatePathQuery checks the `filePath` argument passed to the `gatsbyPath` field on Gatsby's Page node type. The first rule is that filePath must be absolute - it must begin with `/`. A relative path like `about` or `../about` is rejected because the resolver joins it against src/pages internally and a leading slash is the contract. The error message echoes the corrected form.","triggerScenarios":"Querying `page.gatsbyPath(filePath: \"about\")` or any filePath without a leading slash in a GraphQL query, page component, or static query. Triggered during GraphQL validation/resolution of the gatsbyPath field.","commonSituations":"Copying a path from a url bar (no leading slash), constructing filePath dynamically without normalizing, or migrating from an older API that accepted relative paths.","solutions":["Prefix the filePath with `/`, e.g. gatsbyPath(filePath: \"/about\").","When building filePath dynamically, ensure the value starts with `/`: const p = path.startsWith('/') ? path : '/' + path.","Use the corrected value shown in the error message verbatim."],"exampleFix":"// before\nexport const query = graphql`\n  query {\n    page(path: { eq: \"about\" }) {\n      gatsbyPath(filePath: \"about\")\n    }\n  }\n`\n\n// after\nexport const query = graphql`\n  query {\n    pagePage {\n      gatsbyPath(filePath: \"/about\")\n    }\n  }\n`","handlingStrategy":"validation","validationCode":"function ensureLeadingSlash(filePath) {\n  if (typeof filePath !== 'string' || !filePath.startsWith('/')) {\n    throw new Error(`filePath must start with '/': ${filePath}`);\n  }\n  return filePath;\n}","typeGuard":"function isAbsolutePathLike(p) {\n  return typeof p === 'string' && p.startsWith('/');\n}","tryCatchPattern":null,"preventionTips":["Always write gatsbyPath filePath literals with a leading slash.","When interpolating, normalize: const fp = p.startsWith('/') ? p : '/' + p."],"tags":["gatsby-plugin-page-creator","graphql","validation","gatsbypath"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}