{"record":{"id":"3285beb7369217c2","repo":"gatsbyjs/gatsby","slug":"invalid-repl-redirecttemplate-specified-codepe","errorCode":null,"errorMessage":"Invalid REPL redirectTemplate specified: \"${codepen.redirectTemplate}\"","messagePattern":"Invalid REPL redirectTemplate specified: \"(.+?)\"","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-remark-code-repls/src/gatsby-node.js","lineNumber":32,"sourceCode":"  { actions, reporter },\n  {\n    directory = OPTION_DEFAULT_REPL_DIRECTORY,\n    codepen = OPTION_DEFAULT_CODEPEN,\n  } = {}\n) => {\n  codepen = { ...OPTION_DEFAULT_CODEPEN, ...codepen }\n  if (!directory.endsWith(`/`)) {\n    directory += `/`\n  }\n\n  const { createPage } = actions\n\n  if (!fs.existsSync(directory)) {\n    reporter.panic(`Invalid REPL directory specified: \"${directory}\"`)\n  }\n\n  if (!fs.existsSync(codepen.redirectTemplate)) {\n    reporter.panic(\n      `Invalid REPL redirectTemplate specified: \"${codepen.redirectTemplate}\"`\n    )\n  }\n\n  try {\n    const files = await readdir(directory)\n    if (files.length === 0) {\n      console.warn(`Specified REPL directory \"${directory}\" contains no files`)\n\n      return\n    }\n\n    // escape backslashes for windows\n    const resolvedDirectory = resolve(directory)\n    files.forEach(file => {\n      if (extname(file) === `.js` || extname(file) === `.jsx`) {\n        const parsedFile = parse(file)\n        const relativeDir = parsedFile.dir.replace(`${resolvedDirectory}`, ``)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-remark-code-repls/src/gatsby-node.js#L14-L50","documentation":"In gatsby-remark-code-repls createPages (gatsby-node.js:31-35), after validating the directory exists, the plugin checks fs.existsSync(codepen.redirectTemplate). The redirectTemplate (merged from OPTION_DEFAULT_CODEPEN defaults and user-provided codepen options) must be a path to a React component file that serves as the redirect page template. If this file doesn't exist, reporter.panic fires.","triggerScenarios":"Using the default codepen.redirectTemplate path that doesn't exist in the project. Setting a custom redirectTemplate path that points to a non-existent file. The template file was moved or deleted.","commonSituations":"Not providing a redirectTemplate and the default path doesn't match the project structure. Moving the template file without updating the plugin config. Fresh setup where the template component hasn't been created yet.","solutions":["Create the redirect template file (a React component that renders the CodePen redirect form)","Point codepen.redirectTemplate to an existing component: codepen: { redirectTemplate: `${__dirname}/src/templates/codepen-redirect.js` }","Verify the path resolves correctly relative to cwd"],"exampleFix":"// before: redirectTemplate doesn't exist\noptions: {\n  codepen: {\n    redirectTemplate: `./src/templates/codepen-redirect.js`,\n  },\n}\n// file doesn't exist → panic\n\n// after: create the template file\n// src/templates/codepen-redirect.js\nimport React from 'react'\n\nexport default function CodePenRedirect({ pageContext }) {\n  return (\n    <form action={pageContext.action} method=\"POST\">\n      <input type=\"hidden\" name=\"data\" value={pageContext.payload} />\n    </form>\n  )\n}","handlingStrategy":"validation","validationCode":"const fs = require('fs')\nconst path = require('path')\n\nconst templatePath = path.resolve(process.cwd(), options.codepen?.redirectTemplate)\nif (!fs.existsSync(templatePath)) {\n  throw new Error(`Redirect template not found: ${templatePath}`)\n}\nif (!templatePath.endsWith('.js') && !templatePath.endsWith('.jsx') && !templatePath.endsWith('.tsx')) {\n  throw new Error(`Redirect template must be a .js/.jsx/.tsx file: ${templatePath}`)\n}","typeGuard":"import fs from 'fs'\n\nfunction isValidTemplateFile(filePath: string): boolean {\n  return fs.existsSync(filePath) &&\n    /\\.(js|jsx|tsx)$/i.test(filePath)\n}","tryCatchPattern":null,"preventionTips":["Create the redirect template component before configuring the plugin","Use absolute paths for codepen.redirectTemplate","Verify template file existence in a pre-build validation step"],"tags":["configuration","filesystem","validation","code-repls"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}