{"record":{"id":"21e278a185dd35cc","repo":"gatsbyjs/gatsby","slug":"error-in-modulepath","errorCode":null,"errorMessage":"Error in \"${modulePath}\":","messagePattern":"Error in \"(.+?)\":","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/bootstrap/resolve-module-exports.ts","lineNumber":232,"sourceCode":"      if (!moduleFilePath) {\n        return []\n      }\n\n      const rawImportedModule = await import(\n        maybeAddFileProtocol(moduleFilePath)\n      )\n\n      // If the module is cjs, the properties we care about are nested under a top-level `default` property\n      const importedModule = preferDefault(rawImportedModule)\n\n      return Object.keys(importedModule).filter(\n        exportName => exportName !== `__esModule`\n      )\n    } catch (error) {\n      if (!testImportError(modulePath, error)) {\n        // if module exists, but requiring it cause errors,\n        // show the error to the user and terminate build\n        report.panic(`Error in \"${modulePath}\":`, error)\n      }\n    }\n  } else {\n    return staticallyAnalyzeExports(modulePath, resolver)\n  }\n\n  return []\n}\n","sourceCodeStart":214,"sourceCodeEnd":241,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/bootstrap/resolve-module-exports.ts#L214-L241","documentation":"Thrown by resolve-module-exports when dynamically importing a plugin module succeeds in resolution but throws a non-test error at require/import time. The handler checks testImportError (errors considered acceptable to ignore); if it is not ignorable, it panics with the module path and the original error so the user sees the cause. This is the runtime-error-on-import branch, distinct from the SyntaxError branch.","triggerScenarios":"Importing the module triggers code execution that throws (e.g. the module calls a missing function at top level, references undefined config, or fails an assertion); testImportError returns false so the error is surfaced rather than swallowed.","commonSituations":"A plugin module references process.env values or filesystem paths that only exist at runtime; top-level code in the module throws because a dependency it expects is not installed; the module uses an API removed in the current Gatsby version.","solutions":["Inspect the attached `error` object in the panic output: it carries the original thrown error and stack from inside the module.","Open modulePath and fix the top-level code that throws, or wrap it so it only runs inside the intended lifecycle hook.","Ensure all dependencies the module imports at top level are installed and resolvable.","If the module is incompatible with the Gatsby version, pin a compatible version or update the module."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Detect import-time failures in your own plugin modules during dev\ntry {\n  require(modulePath)\n} catch (e) {\n  console.error('Plugin import failed:', e)\n}","typeGuard":null,"tryCatchPattern":"// Wrap the dynamic import to capture the original error:\ntry {\n  const mod = await import(modulePath)\n} catch (e) {\n  console.error(`Import of ${modulePath} threw`, e)\n  throw e\n}","preventionTips":["Keep top-level module code side-effect-free; move logic into lifecycle hooks.","Ensure all imports your module needs are installed.","Pin plugin versions compatible with your Gatsby major."],"tags":["modules","plugin","import","runtime-error"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}