{"record":{"id":"d777f9b4c2f3d5ce","repo":"vitejs/vite","slug":"module-runner-import-meta-resolve-is-not-suppo","errorCode":null,"errorMessage":"[module runner] \"import.meta.resolve\" is not supported.","messagePattern":"\\[module runner\\] \"import\\.meta\\.resolve\" is not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/module-runner/createImportMeta.ts","lineNumber":26,"sourceCode":"    throw new Error(\n      `[module runner] Dynamic access of \"import.meta.env\" is not supported. Please, use \"import.meta.env.${String(p)}\" instead.`,\n    )\n  },\n})\n\nexport function createDefaultImportMeta(\n  modulePath: string,\n): ModuleRunnerImportMeta {\n  const href = posixPathToFileHref(modulePath)\n  const filename = modulePath\n  const dirname = posixDirname(modulePath)\n  return {\n    filename: isWindows ? toWindowsPath(filename) : filename,\n    dirname: isWindows ? toWindowsPath(dirname) : dirname,\n    url: href,\n    env: envProxy,\n    resolve(_id: string, _parent?: string) {\n      throw new Error('[module runner] \"import.meta.resolve\" is not supported.')\n    },\n    // should be replaced during transformation\n    glob() {\n      throw new Error(\n        `[module runner] \"import.meta.glob\" is statically replaced during ` +\n          `file transformation. Make sure to reference it by the full name.`,\n      )\n    },\n  }\n}\n\n/**\n * Create import.meta object for Node.js.\n */\nexport function createNodeImportMeta(\n  modulePath: string,\n): ModuleRunnerImportMeta {\n  const defaultMeta = createDefaultImportMeta(modulePath)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/module-runner/createImportMeta.ts#L8-L44","documentation":"The default module-runner import.meta object implements `resolve()` as a function that always throws. Resolution of arbitrary specifiers at runtime requires filesystem/resolve machinery that the default runner does not provide. The Node-specific variant (`createNodeImportMeta`) does implement `resolve`, so the throw only occurs under the default meta.","triggerScenarios":"Calling `import.meta.resolve(id)` in code executed by a module runner that was constructed with the default `createImportMeta` (no custom `createImportMeta` option and not the Node evaluator path).","commonSituations":"Sharing a module between a bundler build and the runner where the bundler supports `import.meta.resolve` but the runner default does not. Library code that probes `import.meta.resolve` for feature detection.","solutions":["Pass a custom `createImportMeta` to the ModuleRunner that supplies a working `resolve` (the runner's `createImportMetaResolver` helper can back it).","Use the Node module-runner evaluator path (`createNodeImportMeta`) which implements `resolve`.","Avoid `import.meta.resolve` in runner-executed code; resolve specifiers at build time or via the runner transport instead."],"exampleFix":"// before\nnew ModuleRunner({ transport, /* default createImportMeta - resolve throws */ })\n// module calls: import.meta.resolve('./foo')\n\n// after\nimport { createNodeImportMeta } from 'vite/module-runner'\nnew ModuleRunner({ transport, createImportMeta: createNodeImportMeta })","handlingStrategy":"validation","validationCode":"import { createNodeImportMeta } from 'vite/module-runner'\nfunction runnerOptionsNeedsNodeResolve(opts: { createImportMeta?: unknown }) {\n  // if no custom createImportMeta provided AND code uses import.meta.resolve, swap in the Node variant\n  return opts.createImportMeta == null\n}\n// usage: if (runnerOptionsNeedsNodeResolve(opts)) opts.createImportMeta = createNodeImportMeta","typeGuard":"function importMetaResolveAvailable(meta: any): boolean {\n  try { return typeof meta.resolve === 'function' && meta.resolve !== createDefaultImportMetaResolveStub() } catch { return false }\n}","tryCatchPattern":"try {\n  return import.meta.resolve(id)\n} catch (e) {\n  if (e instanceof Error && /import.meta.resolve.*not supported/.test(e.message)) {\n    // resolve via an alternative (e.g. node:module createRequire)\n  } else throw e\n}","preventionTips":["If runner code needs resolve(), pass createNodeImportMeta (or a custom createImportMeta) to ModuleRunner.","Avoid import.meta.resolve in code shared between bundler and default runner."],"tags":["module-runner","import-meta-resolve","ssr"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}