From 62c7076cab1d743af546cfe3debab934436629c9 Mon Sep 17 00:00:00 2001 From: yamachi4416 Date: Mon, 6 Apr 2026 23:47:53 +0900 Subject: [PATCH] fix(runtime): avoid error when vue/test-utils is not installed --- src/runtime/shared/vue-wrapper-plugin.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/runtime/shared/vue-wrapper-plugin.ts b/src/runtime/shared/vue-wrapper-plugin.ts index cf78e95c5..a60616b45 100644 --- a/src/runtime/shared/vue-wrapper-plugin.ts +++ b/src/runtime/shared/vue-wrapper-plugin.ts @@ -1,11 +1,24 @@ -import { config } from '@vue/test-utils' import type { VueWrapper } from '@vue/test-utils' -type Options = ReturnType +interface Options { + hasNuxtPage(): boolean +} const PLUGIN_NAME = 'nuxt-test-utils' +// @vue/test-utils is optional +// If import fails, hasNuxtPage always returns false +const config = await import('@vue/test-utils') + .then(r => r.config) + .catch(() => undefined) + export function getVueWrapperPlugin(): Options { + if (!config) { + return { + hasNuxtPage: () => false, + } + } + const installed = config.plugins.VueWrapper.installedPlugins .find(({ options }) => options?._name === PLUGIN_NAME)