{"record":{"id":"0619582687ae28b3","repo":"facebook/docusaurus","slug":"invalid-module-path-of-type-name-typeof-modulep","errorCode":null,"errorMessage":"Invalid module path of type \"name=${typeof modulePath}\" with value \"name=${modulePath}\"","messagePattern":"Invalid module path of type \"name=(.+?)\" with value \"name=(.+?)\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/moduleUtils.ts","lineNumber":33,"sourceCode":"  fsCache: true,\n  // Bypass Node.js runtime require cache for hot reloads\n  moduleCache: false,\n\n  interopDefault: true,\n  debug: DEBUG,\n});\n\n/*\njiti is able to load ESM, CJS, JSON, TS modules\n */\nexport async function loadFreshModule(\n  modulePath: string,\n  options?: {\n    default?: true; // Use this when only the default export matters\n  },\n): Promise<unknown> {\n  if (typeof modulePath !== 'string') {\n    throw new Error(\n      logger.interpolate`Invalid module path of type \"name=${typeof modulePath}\" with value \"name=${modulePath}\"`,\n    );\n  }\n  try {\n    const module = await jiti.import(modulePath, {\n      default: options?.default,\n    });\n\n    if (DEBUG) {\n      console.log('Jiti module loaded', {\n        modulePath,\n        options,\n        type: typeof module,\n        keys:\n          module && typeof module === 'object'\n            ? Object.keys(module)\n            : undefined,\n        module,","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/moduleUtils.ts#L15-L51","documentation":"Thrown by loadFreshModule() as a type guard before attempting to load anything: if modulePath is not a string, the function refuses to proceed. This guards jiti.import (which expects a string) from being called with a number, object, undefined, or null that would otherwise surface as an opaque internal error.","triggerScenarios":"Calling loadFreshModule with a non-string value — typically because a config lookup returned undefined (e.g. a plugin path option was not set and the variable is undefined), or a number was passed where a path string was expected. The interpolated message reports both the typeof and the coerced value to aid debugging.","commonSituations":"A docusaurus.config.js or plugin config value is undefined at the point it is passed to loadFreshModule (e.g. a presets entry that is missing its path). Destructuring a config object and passing the wrong field. A programmatic caller that loaded a path from JSON where the field was numeric or absent.","solutions":["Inspect the error's interpolated value (and typeof) to see what non-string was passed.","Trace the call site backward to find where modulePath was sourced and ensure that variable is a string path before calling loadFreshModule.","Add a default or guard at the source so the path is never undefined — e.g. read from config with a fallback.","If the path comes from user config, validate it with typeof check and emit a clearer user-facing error before reaching loadFreshModule."],"exampleFix":"// before\nconst presetPath = config.presets[0].path; // undefined if misconfigured\nawait loadFreshModule(presetPath);\n\n// after\nif (typeof presetPath !== 'string') {\n  throw new Error('presets[0].path must be a string module path');\n}\nawait loadFreshModule(presetPath);","handlingStrategy":"type-guard","validationCode":"if (typeof modulePath !== 'string' || modulePath.length === 0) {\n  throw new Error(`Module path must be a non-empty string, got ${typeof modulePath}: ${modulePath}`);\n}\nawait loadFreshModule(modulePath, options);","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  await loadFreshModule(modulePath, options);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Invalid module path')) {\n    // the caller passed a non-string; fix the source of modulePath\n  }\n  throw err;\n}","preventionTips":["Always type modulePath as string at the API boundary and validate before forwarding to loadFreshModule.","When reading a path from config, default to a concrete value or fail fast with a clear config error.","Use TypeScript strict null checks so undefined paths surface at compile time."],"tags":["module-loader","validation","type-guard","config"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}