{"record":{"id":"bb91fb4350649cde","repo":"gatsbyjs/gatsby","slug":"error-in-gatsby-remark-code-repls-plugin-c","errorCode":null,"errorMessage":"\n      Error in gatsby-remark-code-repls plugin: cannot read directory ${directory}.\n      More details can be found in the error reporting below.\n      ","messagePattern":"\n      Error in gatsby-remark-code-repls plugin: cannot read directory (.+?)\\.\n      More details can be found in the error reporting below\\.\n      ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-remark-code-repls/src/gatsby-node.js","lineNumber":95,"sourceCode":"          html: codepen.html,\n          js: code,\n          js_external: codepen.externals.join(`;`),\n          js_pre_processor: `babel`,\n          layout: `left`,\n          css,\n        })\n        createPage({\n          path: slug,\n          component: normalizePath(resolve(codepen.redirectTemplate)),\n          context: {\n            action,\n            payload,\n          },\n        })\n      }\n    })\n  } catch (error) {\n    reporter.panic(\n      `\n      Error in gatsby-remark-code-repls plugin: cannot read directory ${directory}.\n      More details can be found in the error reporting below.\n      `,\n      error\n    )\n  }\n}\n","sourceCodeStart":77,"sourceCodeEnd":104,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-remark-code-repls/src/gatsby-node.js#L77-L104","documentation":"In gatsby-remark-code-repls createPages (gatsby-node.js:37-102), the plugin wraps the recursive readdir(directory) call and all file processing (reading, parsing, CSS matching, createPage) in a try-catch. If any operation throws — permission denied reading the directory, a file read error, a createPage error, or an error in the CSS matching logic — reporter.panic fires with the directory path and the original error object.","triggerScenarios":"Permission denied reading files in the directory. A file in the directory is not readable (locked, permission issue). recursive-readdir encounters a symlink loop or other file system error. createPage throws due to duplicate slugs or invalid page data. An error reading the matching CSS file (non-ENOENT errors from line 67's throw).","commonSituations":"File permission issues on the examples directory. Symlink loops causing readdir to fail. Duplicate file names creating slug collisions in createPage. Race condition where a file is deleted between readdir and readFileSync.","solutions":["Read the 'error' object in the panic output — it contains the specific underlying error (ENOENT, EACCES, EEXIST, etc.)","Fix file permissions: chmod -R +r <directory>","Remove or fix symlink loops in the directory","Rename duplicate files that create slug collisions","Ensure all files in the directory are valid and readable"],"exampleFix":"// before: permission issue or unreadable file\n// Error output will show the specific error code\n\n// after: fix permissions\nchmod -R +r src/examples/\n// or remove problematic files identified by the error","handlingStrategy":"try-catch","validationCode":"// Pre-build: verify all files in the REPL directory are readable\nconst fs = require('fs')\nconst path = require('path')\n\nfunction validateReplDirectory(dir) {\n  const entries = fs.readdirSync(dir, { recursive: true })\n  for (const entry of entries) {\n    const fullPath = path.join(dir, entry)\n    try {\n      fs.accessSync(fullPath, fs.constants.R_OK)\n    } catch {\n      console.warn(`File not readable: ${fullPath}`)\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"// The plugin wraps the entire readdir+processing in try-catch.\n// As a consumer, you can pre-validate file readability:\nconst files = fs.readdirSync(directory)\nfor (const file of files) {\n  try {\n    fs.readFileSync(path.join(directory, file), 'utf8')\n  } catch (err) {\n    console.error(`Cannot read ${file}:`, err.message)\n  }\n}","preventionTips":["Ensure all files in the REPL directory have read permissions (chmod +r)","Remove symlink loops or broken symlinks from the directory","Avoid duplicate file names that create slug collisions","Run a pre-build file validation check on the examples directory"],"tags":["filesystem","runtime-error","code-repls","permissions"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}