diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 3834788611fc2e..0f3ba9c2b2c304 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -645,11 +645,15 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // build CSS handling ---------------------------------------------------- - const cssScopeTo = ( - this.getModuleInfo(id)?.meta?.vite as - | CustomPluginOptionsVite - | undefined - )?.cssScopeTo + const cssScopeTo = + // NOTE: `this.getModuleInfo` can be undefined when the plugin is called directly + // adding `?.` temporary to avoid unocss from breaking + // TODO: remove `?.` after `this.getModuleInfo` in Vite 7 + ( + this.getModuleInfo?.(id)?.meta?.vite as + | CustomPluginOptionsVite + | undefined + )?.cssScopeTo // record css if (!inlined) {