{"record":{"id":"a23f4c9c807dea7d","repo":"DIYgod/RSSHub","slug":"directoryimport-is-not-available-in-worker-builds","errorCode":null,"errorMessage":"directoryImport is not available in Worker builds","messagePattern":"directoryImport is not available in Worker builds","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/utils/directory-import.worker.ts","lineNumber":13,"sourceCode":"// No-op shim for directory-import in Cloudflare Workers\n// directoryImport is only used in dev mode, Worker builds use pre-built routes\n\nexport type DirectoryImportOptions = {\n    targetDirectoryPath: string;\n    importPattern?: RegExp;\n    includeSubdirectories?: boolean;\n};\n\nexport const directoryImport = (_options: DirectoryImportOptions): Record<string, unknown> => {\n    // This should never be called in Worker builds\n    // Worker builds use pre-built routes from routes-worker.js\n    throw new Error('directoryImport is not available in Worker builds');\n};\n","sourceCodeStart":1,"sourceCodeEnd":15,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/utils/directory-import.worker.ts#L1-L15","documentation":"directory-import.worker.ts is a build-time shim that replaces the real directory-import module in Worker bundles. Because Workers cannot perform filesystem directory scans at runtime, the shim throws immediately to make any accidental call visible. Worker builds are expected to use pre-built route lists (routes-worker.js) instead.","triggerScenarios":"Code that calls directoryImport({...}) is reachable in the Worker bundle - typically because a dynamic route loader or dev-only utility was not excluded from the Worker build graph.","commonSituations":"A new route or utility that auto-discovers files via directoryImport is imported (directly or transitively) by Worker-bundled code; a refactor that moves dev-mode code into a shared module pulled into the Worker entry.","solutions":["Ensure directoryImport is only referenced from the Node/dev entry, never from the Worker entry.","Pre-build the route list at build time and import the generated module in the Worker bundle instead.","Mark the offending import as external or exclude it via the Worker bundler config."],"exampleFix":"// before (Worker bundle)\nconst routes = directoryImport({ targetDirectoryPath: './routes' });\n// after\nimport routes from './generated/routes-worker.js';","handlingStrategy":"try-catch","validationCode":"function isWorkerBuild(): boolean {\n  return typeof (globalThis as any).caches !== 'undefined' && typeof (process as any)?.cwd !== 'function';\n}\nif (isWorkerBuild() && usesDirectoryImport) { /* use pre-built routes */ }","typeGuard":"const isWorkerContext = (): boolean =>\n  typeof (globalThis as any).WRAPERS || (typeof window === 'undefined' && typeof (globalThis as any).caches !== 'undefined' && !(globalThis as any).process?.versions?.node);","tryCatchPattern":"try {\n  return directoryImport(opts);\n} catch (e) {\n  if (/not available in Worker builds/.test((e as Error).message)) {\n    return import('./generated/routes-worker.js');\n  }\n  throw e;\n}","preventionTips":["Never import the real directory-import module from Worker-bundled code - keep it in the Node entry only.","Generate a static route list at build time and consume it from the Worker bundle.","Add a bundler externals rule so directory-import is excluded from the Worker graph."],"tags":["cloudflare-workers","shim","build","directory-import"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}