{"record":{"id":"d7ac089a41e17502","repo":"gatsbyjs/gatsby","slug":"pagecreator-to-query-node-gatsbypath-the-filep-d7ac08","errorCode":null,"errorMessage":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit index.\nPlease change this to: \"${filePath.replace(/index$/, ``)}\"","messagePattern":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit index\\.\nPlease change this to: \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-page-creator/src/validate-path-query.ts","lineNumber":28,"sourceCode":"    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(\n      `PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit index.\nPlease change this to: \"${filePath.replace(/index$/, ``)}\"`\n    )\n  }\n\n  const absolutePath = systemPath.join(process.cwd(), `src/pages`, filePath)\n\n  const file = _.flatten(\n    extensions.map(ext =>\n      [``, `${systemPath.sep}index`].map(index => {\n        try {\n          return require.resolve(absolutePath + index + ext)\n        } catch (e) {\n          return false\n        }\n      })\n    )\n  ).filter(Boolean) as Array<string>","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-page-creator/src/validate-path-query.ts#L10-L46","documentation":"validatePathQuery's fourth rule: filePath must NOT end with `index`. The regex /index$/ matches a trailing `index` (the conventional filename for the root of a route). Because the route root is the directory itself, the filePath should stop at the directory. The message shows the index-stripped form.","triggerScenarios":"Passing gatsbyPath(filePath: \"/about/index\") or \"/blog/index\") - any filePath ending in the word index.","commonSituations":"Translating the actual index.js/index.tsx filename into the query; building the path from the file basename without filtering `index`; coming from frameworks where /about/index is the canonical route.","solutions":["Drop the trailing `index`, e.g. use \"/about/\" or \"/about\" instead of \"/about/index\".","Strip it programmatically when generating paths: filePath.replace(/index$/, '').","Use the value suggested in the error message."],"exampleFix":"// before\ngatsbyPath(filePath: \"/about/index\")\n\n// after\ngatsbyPath(filePath: \"/about/\")","handlingStrategy":"validation","validationCode":"function stripTrailingIndex(filePath) {\n  return /index$/.test(filePath) ? filePath.replace(/index$/, '') : filePath;\n}","typeGuard":"function hasNoTrailingIndex(p) {\n  return typeof p === 'string' && !/index$/.test(p);\n}","tryCatchPattern":null,"preventionTips":["Do not append /index to gatsbyPath filePath; end at the directory.","Filter 'index' out of any generated route segments."],"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"}