{"record":{"id":"4498c126c288d286","repo":"deepseek-ai/deepseek-harness","slug":"client-modules-client-modules-id-client-js-req","errorCode":null,"errorMessage":"client-modules: ${CLIENT_MODULES_ID}/client.js requested external \"${specifier}\" before the module system existed","messagePattern":"client-modules: (.+?)/client\\.js requested external \"(.+?)\" before the module system existed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/client/modules/src/index.ts","lineNumber":256,"sourceCode":" * @param graph - the composed entry graph.\n * @returns head rows in execution order: queue script, preload scripts, graph global.\n */\nexport function bootInjections(graph: WebBootGraph): IndexInjection[] {\n  const bootstrapId = JSON.stringify(CLIENT_MODULES_ID)\n  const queue = `(()=>{\nconst pendingQueue=[]\nwindow.__ModuleLoader__={\n  mode:\"queue\",\n  pendingQueue,\n  load(registration){pendingQueue.push(registration)},\n  create(options){\n    if(this.mode!==\"queue\")throw new Error(\"client-modules: window.__ModuleLoader__.create called after module-system boot\")\n    const index=pendingQueue.findIndex(registration=>registration.id===${bootstrapId})\n    const registration=pendingQueue[index]\n    if(registration===undefined)throw new Error(\"client-modules: HTML did not preload ${CLIENT_MODULES_ID}/client.js\")\n    pendingQueue.splice(index,1)\n    const exports=registration.factory(specifier=>{\n      throw new Error('client-modules: ${CLIENT_MODULES_ID}/client.js requested external \"'+specifier+'\" before the module system existed')\n    })\n    if(typeof exports!==\"object\"||exports===null||typeof exports.createClientModuleSystem!==\"function\"||typeof exports.apply!==\"function\"){\n      throw new Error(\"client-modules: ${CLIENT_MODULES_ID}/client.js did not export the bootstrap module face\")\n    }\n    return exports.createClientModuleSystem(this,{id:registration.id,exports},options)\n  }\n}\n})()`\n  const preload = PARSER_PRELOAD_IDS.map(id => graph.entries.find(entry => entry.id === id))\n    .filter((entry): entry is WebBootEntry => entry !== undefined)\n    .map((entry): IndexInjection => ({ kind: 'script-src', placement: 'head', src: entry.url }))\n  return [\n    { kind: 'script', placement: 'head', text: queue },\n    ...preload,\n    { kind: 'global', name: '__DSH_BOOT__', value: graph },\n  ]\n}\n","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/client/modules/src/index.ts#L238-L274","documentation":"Thrown while the bootstrap bundle's factory executes inside window.__ModuleLoader__.create(). The only require available at that instant is a stub whose every call throws, because the shared module table does not exist until createClientModuleSystem returns. Any external module the '@deepseek-ai/dsh-client-modules' client bundle requests synchronously at factory time — instead of bundling it privately or deferring the import — trips this error. It is a build/packaging defect in the bootstrap bundle, not a condition runtime callers create.","triggerScenarios":"The built lib/client.js of dsh-client-modules carries an externalized top-level value import, so its factory calls the stub require(specifier) during create(). Typical causes: a bundler-config regression that externalizes a module the bootstrap half imports at factory scope, a hand-edited tsdown.client.ts external list, or version skew where an old bundle is paired with the current HTML queue protocol.","commonSituations":"Upgrading the client bundling toolchain and forgetting that the bootstrap bundle must stay self-contained at factory time; locally adding an `external` entry to speed up builds; partial `pnpm run build` after protocol changes leaving one stale bundle.","solutions":["Rebuild the bootstrap bundle from current sources: `pnpm --filter @deepseek-ai/dsh-client-modules bundle` (or a full `pnpm run build`) and hard-reload.","Inspect the client bundle preset (packages/client tsdown config) for an `external` entry covering a module the bootstrap half imports as a value at top level; remove it or make the import lazy so the request happens after the system exists.","Smoke the artifact offline: evaluate lib/client.js in a VM under a queue stub and invoke the factory with a throwing require — any factory-time request throws by construction.","Confirm no stale copy of client.js is being served (rev query mismatch, copied static directory)."],"exampleFix":"// before — tsdown.client.ts externalizes a value import for the bootstrap bundle\nclientBundle('modules', ['lib/types/index.js'], { external: ['@deepseek-ai/dsh-client-runtime'] })\n\n// after — the bootstrap bundle stays self-contained at factory time\nclientBundle('modules', ['lib/types/index.js'])","handlingStrategy":"try-catch","validationCode":"import vm from 'node:vm'\nimport { readFileSync } from 'node:fs'\n// offline smoke: the bootstrap factory must not request externals before the system exists\nconst src = readFileSync('packages/client/modules/lib/client.js', 'utf8')\nconst pendingQueue = []\nconst sandbox = { window: { __ModuleLoader__: { mode: 'queue', load: r => pendingQueue.push(r) } } }\nvm.createContext(sandbox)\nvm.runInContext(src, sandbox)\nconst reg = pendingQueue.find(r => r.id === '@deepseek-ai/dsh-client-modules')\nreg.factory(spec => { throw new Error(`premature external request: ${spec}`) }) // must not throw","typeGuard":null,"tryCatchPattern":"try {\n  system = window.__ModuleLoader__.create(options)\n} catch (error) {\n  reportBootFailure(error) // advise rebuilding @deepseek-ai/dsh-client-modules and hard-reloading\n  throw error\n}","preventionTips":["Keep the bootstrap client bundle free of factory-time external requests: bundle dependencies privately or defer imports until after boot.","Run the keyless web replay smoke after touching bundler configuration.","Rebuild all client packages together; avoid partial builds across protocol changes."],"tags":["browser","module-loader","bundling","externals"],"backgroundTag":"module-init-order","analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}