{"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/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/pools/rpc.ts#L261-L297","documentation":"Internal assertion in the transform RPC method: it routes raw transforms through the reserved __vitest_vm__ Vite environment, which Vitest registers automatically for in-process module transformation. If that environment is absent, the framework's own setup is broken — explicitly flagged as a bug to report, not a user config issue.","triggerScenarios":"rpc.transform is called and project.vite.environments.__vitest_vm__ is undefined, at packages/vitest/src/node/pools/rpc.ts:277-279. The __vitest_vm__ environment is created by Vitest's Vite plugin; its absence means the plugin did not register correctly.","commonSituations":"Vitest Vite plugin not loaded (custom server setup that bypasses the plugin); a severe Vite/Vitest version incompatibility; a plugin that clears environments; an experimental/custom Vitest entrypoint that skips plugin registration.","solutions":["Report as a Vitest bug with reproduction.","Ensure you are using the standard Vitest entry (vitest/node) and not bypassing its Vite plugin.","Check Vitest and Vite version compatibility and upgrade/downgrade to a matched pair.","Remove custom Vite plugins that mutate server.environments to isolate the cause."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await vitest.start()\n} catch (e) {\n  if (e.message.includes('The VM environment was not defined in the Vite config')) {\n    console.error('Vitest internal: __vitest_vm__ environment missing. Report as a bug.')\n  }\n  throw e\n}","preventionTips":["Use the standard vitest/node entry so the Vitest Vite plugin registers __vitest_vm__.","Keep Vitest and Vite versions compatible.","Avoid custom Vite plugins that mutate server.environments."],"tags":["rpc","internal-bug","environment","transform","assertion"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}