{"id":"621e03027622ea77","repo":"vitejs/vite","slug":"fetchmodule-is-disabled-in-this-environment","errorCode":null,"errorMessage":"fetchModule is disabled in this environment","messagePattern":"fetchModule is disabled in this environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/server/environment.ts","lineNumber":161,"sourceCode":"    this._crawlEndFinder = setupOnCrawlEnd()\n\n    this._remoteRunnerOptions = context.remoteRunner ?? {}\n    this._skipFsCheck = !!(\n      context.transport &&\n      !(isWebSocketServer in context.transport) &&\n      context.transport.skipFsCheck\n    )\n\n    this.hot = context.transport\n      ? isWebSocketServer in context.transport\n        ? context.transport\n        : normalizeHotChannel(context.transport, context.hot)\n      : normalizeHotChannel({}, context.hot)\n\n    this.hot.setInvokeHandler({\n      fetchModule: (id, importer, options) => {\n        if (context.disableFetchModule) {\n          throw new Error('fetchModule is disabled in this environment')\n        }\n        return this.fetchModule(id, importer, options)\n      },\n      getBuiltins: async () => {\n        return this.config.resolve.builtins.map((builtin) =>\n          typeof builtin === 'string'\n            ? { type: 'string', value: builtin }\n            : { type: 'RegExp', source: builtin.source, flags: builtin.flags },\n        )\n      },\n    })\n\n    this.hot.on(\n      'vite:invalidate',\n      ({ path, message, firstInvalidatedBy }, client) => {\n        this.invalidateModule(\n          {\n            path,","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/server/environment.ts#L143-L179","documentation":"The hot channel's invoke handler for fetchModule at packages/vite/src/node/server/environment.ts:161 throws when context.disableFetchModule is true. Environments that opt out of module fetching over the hot channel (e.g. remote runner transports, some bundled-dev setups) set this flag; any caller that still issues a fetchModule invoke gets rejected.","triggerScenarios":"Calling environment.hot.send / invoke('fetchModule', ...) (directly or via server.transport) on an environment whose context.disableFetchModule = true; a plugin or framework runtime that always calls fetchModule without checking support; mismatched server/client expectations where the client expects to fetch modules but the environment disabled it.","commonSituations":"Custom/remote environments that resolve modules themselves; bundled-dev mode where deps optimizer is disabled; frameworks (RSC, SSR runners) that ship their own module loading and turn fetchModule off.","solutions":["Do not call fetchModule on environments where it is disabled — fetch modules through the path the environment intends (e.g. its remoteRunner or transport).","When constructing the environment, leave disableFetchModule unset (default) if you need module fetching.","Guard callers with environment.runner / transport feature detection before issuing fetchModule."],"exampleFix":"// before\nawait environment.hot.invoke('fetchModule', id)\n\n// after\nif (!context.disableFetchModule) {\n  await environment.hot.invoke('fetchModule', id)\n} else {\n  // use the environment's native module loader\n}","handlingStrategy":"type-guard","validationCode":"function canFetchModule(ctx: { disableFetchModule?: boolean }): boolean {\n  return !ctx.disableFetchModule\n}\nif (canFetchModule(envContext)) {\n  await environment.hot.invoke('fetchModule', id, importer)\n}","typeGuard":"function fetchModuleEnabled(env: { hot: { invoke: (m: string) => unknown } } & { disableFetchModule?: boolean }): boolean {\n  return !(env as any).disableFetchModule\n}","tryCatchPattern":"try {\n  await env.hot.invoke('fetchModule', id)\n} catch (e) {\n  if (/fetchModule is disabled/.test((e as Error).message)) {\n    // load the module through the environment's native runner instead\n  } else throw e\n}","preventionTips":["Do not call fetchModule on remote/bundled environments that disable it.","Feature-detect the environment's transport/runner before issuing fetchModule.","Document per environment whether module fetching is supported."],"tags":["environment","fetchmodule","hot-channel","dev-server"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}