{"record":{"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/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/server/environment.ts#L143-L179","documentation":"DevEnvironment registers a fetchModule invoke handler on its hot channel. If context.disableFetchModule is true, the handler throws instead of running fetchModule. This lets a environment opt out of serving transformed module source over its transport (used by some RTE/SSR setups that do not expose modules to clients).","triggerScenarios":"A consumer calls environment.fetchModule (or the hot channel invokes 'fetchModule') on an environment whose DevEnvironmentContext was created with disableFetchModule: true. Common when a runtime tries to pull module source from an environment configured not to serve it.","commonSituations":"Custom runtime/transport adapters calling fetchModule indiscriminately, or copying context options from an SSR environment (which may disable fetchModule) into a context that is then queried for modules.","solutions":["Do not call fetchModule on environments where disableFetchModule is set; check the context before calling.","Construct the environment with disableFetchModule: false (or omit it) if the consumer needs module source.","Route module fetching through an environment that exposes it (e.g. the client/SSR dev environment).","If you control the transport, avoid emitting the fetchModule invoke for disabled environments."],"exampleFix":"// before\nconst env = new DevEnvironment('x', config, { disableFetchModule: true, ... })\nawait env.fetchModule(id)\n// after\nconst env = new DevEnvironment('x', config, { disableFetchModule: false, ... })\nawait env.fetchModule(id)","handlingStrategy":"validation","validationCode":"function assertFetchModuleEnabled(context) {\n  if (context.disableFetchModule) throw new Error('fetchModule is disabled for this environment')\n}\nassertFetchModuleEnabled(context)","typeGuard":"function canFetchModule(context): boolean {\n  return !context.disableFetchModule\n}","tryCatchPattern":"try {\n  return await env.fetchModule(id, importer, opts)\n} catch (e) {\n  if (/fetchModule is disabled/.test(e.message)) return null // graceful skip\n  throw e\n}","preventionTips":["Check context.disableFetchModule before calling fetchModule.","Construct environments with disableFetchModule: false when module serving is needed.","Route module queries to environments that expose them."],"tags":["environments","fetch-module","dev-server","api-misuse"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}