{"record":{"id":"747cf6b82f62011b","repo":"gatsbyjs/gatsby","slug":"pagecreator-to-query-node-gatsbypath-the-filep-747cf6","errorCode":null,"errorMessage":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit the file extension\nPlease change ${filePath} to \"${filePath.replace(/\\.[a-z]+$/i, ``)}\"","messagePattern":"PageCreator: To query node \"gatsbyPath\" the \"filePath\" argument must omit the file extension\nPlease change (.+?) to \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-page-creator/src/validate-path-query.ts","lineNumber":16,"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(\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)","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-page-creator/src/validate-path-query.ts#L1-L34","documentation":"validatePathQuery's second rule: filePath must NOT include a file extension. The regex /\\.[a-z]+$/i matches a trailing extension like `.js`, `.tsx`, `.md`. Because gatsbyPath resolves against src/pages across all supported extensions (js, jsx, ts, tsx, md, mdx...), the caller must give the logical route, not the filename. The message shows the extension-stripped form to use.","triggerScenarios":"Passing gatsbyPath(filePath: \"/about.js\") or \"/blog/post.mdx\" - any filePath ending in a dot followed by letters.","commonSituations":"Copy-pasting the actual filename from src/pages into the query; tooling that auto-completes file paths; refactoring that leaves an old extension in the query.","solutions":["Drop the trailing extension from filePath, e.g. use \"/about\" instead of \"/about.js\".","Strip it programmatically if generated: filePath.replace(/\\.[a-z]+$/i, '').","Use the value suggested in the error message."],"exampleFix":"// before\ngatsbyPath(filePath: \"/about.tsx\")\n\n// after\ngatsbyPath(filePath: \"/about\")","handlingStrategy":"validation","validationCode":"function stripExtension(filePath) {\n  if (/\\.[a-z]+$/i.test(filePath)) {\n    return filePath.replace(/\\.[a-z]+$/i, '');\n  }\n  return filePath;\n}","typeGuard":"function isExtensionless(p) {\n  return typeof p === 'string' && !/\\.[a-z]+$/i.test(p);\n}","tryCatchPattern":null,"preventionTips":["Copy route paths, not file names, into gatsbyPath queries.","Add an eslint rule or pre-commit grep that flags gatsbyPath filePath literals containing extensions."],"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"}