{"record":{"id":"65240462fc7baf5f","repo":"vitest-dev/vitest","slug":"the-vm-environment-was-not-defined-in-the-vite-con","errorCode":null,"errorMessage":"The VM environment was not defined in the Vite config. This is a bug in Vitest. Please, open a new issue with reproduction.","messagePattern":"The VM environment was not defined in the Vite config\\. This is a bug in Vitest\\. Please, open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/pools/rpc.ts","lineNumber":279,"sourceCode":"      return {\n        file: cleanUrl(resolved.id),\n        url: normalizeResolvedIdToUrl(environment, resolved.id),\n        id: resolved.id,\n      }\n    },\n\n    snapshotSaved(snapshot) {\n      vitest.snapshot.add(snapshot)\n    },\n    resolveSnapshotPath(testPath: string) {\n      return vitest.snapshot.resolvePath<ResolveSnapshotPathHandlerContext>(testPath, {\n        config: project.serializedConfig,\n      })\n    },\n    async transform(id) {\n      const environment = project.vite.environments.__vitest_vm__\n      if (!environment) {\n        throw new Error(`The VM environment was not defined in the Vite config. This is a bug in Vitest. Please, open a new issue with reproduction.`)\n      }\n\n      const url = normalizeResolvedIdToUrl(environment, fileURLToPath(id))\n      const result = await environment.transformRequest(url).catch(handleRollupError)\n      return { code: result?.code }\n    },\n    async onQueued(file) {\n      if (methodsOptions.collect) {\n        vitest.state.collectFiles(project, [file])\n      }\n      else {\n        await vitest._testRun.enqueued(project, file)\n      }\n    },\n    async onCollected(files) {\n      if (methodsOptions.collect) {\n        vitest.state.collectFiles(project, files)\n      }","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/node/pools/rpc.ts#L261-L297","documentation":"An internal invariant: the built-in '__vitest_vm__' DevEnvironment must always exist so transformRequest can run code inside the VM sandbox. Unlike the user-facing environment errors, this one explicitly says it is a bug in Vitest, because the VM environment is created by Vitest itself and should never be absent.","triggerScenarios":"The 'transform' RPC handler reads project.vite.environments.__vitest_vm__ and finds it undefined while transforming a module id (used for in-process VM transforms).","commonSituations":"A broken Vitest install, partial build, conflicting Vitest versions across the monorepo, or a custom plugin/config that mutates or deletes environments and accidentally removes '__vitest_vm__'. Almost never a normal user-config mistake.","solutions":["Reinstall node_modules (pnpm install) and rebuild Vitest (pnpm build) to rule out a stale/partial build.","Ensure a single Vitest version across the workspace (pnpm why vitest).","Check custom Vite plugins/hooks (configureServer, config) for code that mutates vite.environments.","If reproducible, open a Vitest issue with the reproduction as the message instructs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const hasVmEnvironment = (vite: { environments?: Record<string, unknown> }): boolean =>\n  Boolean(vite.environments && '__vitest_vm__' in vite.environments)","tryCatchPattern":"try {\n  await rpc.transform(id)\n} catch (err) {\n  if (err instanceof Error && err.message.includes('__vitest_vm__')) {\n  // internal Vitest invariant: rebuild/reinstall and report\n  throw new Error('Vitest VM environment missing - rebuild Vitest and retry', { cause: err })\n  }\n  throw err\n}","preventionTips":["Keep a single Vitest version across the workspace.","Do not mutate vite.environments in custom plugins.","Rebuild after editing Vitest source."],"tags":["internal-bug","environment","vite","vm","transform"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}