Skip to content

Plugin Options Can Be Undefined - Error reading '_name' #1546

@robm-masabi

Description

@robm-masabi

Environment

Operating system macOS 24.6.0
CPU Apple M2 Pro (10 cores)
Node.js version v22.14.0
nuxt/cli version 3.31.2
Package manager yarn@1.22.19
Nuxt version 4.2.2
Nitro version 2.12.9
Builder vite@7.2.7
Config app, authorization, compatibilityDate, components, css, devServer, devtools, dir, hooks, i18n, imports, modules, nitro, primevue, routeRules, runtimeConfig, security, spaLoadingTemplate, ssr, svgo
Modules @pinia/nuxt@0.11.2, @nuxt/eslint@1.10.0, @nuxt/icon@2.1.0, @nuxt/scripts@0.13.0, @nuxt/test-utils@3.23.0, @vueuse/nuxt@14.0.0, nuxt-svgo@4.2.6, pinia-plugin-persistedstate/nuxt@4.7.1, @nuxtjs/i18n@10.2.1, @primevue/nuxt-module@4.4.1, nuxt-security@2.4.0, nuxt-authorization@0.3.5

Reproduction

https://stackblitz.com/edit/github-rjcplztc-5javvanr?file=test%2Fnuxt%2Fapp.spec.ts

Thanks to yamanchi for the reproduction

Describe the bug

When running a vitest suite using the Nuxt environment the library throws an error when attempting to read _name from the destructured options property of the plugin.

According to the TypeScript definition, options is of type any, and therefore its possible to encounter an error when attempting to read the plugin name off of it. This throws an error preventing the test suite from executing.

Using optional chaining when accessing _name inside of the recently-introduced src/runtime/shared/vue-wrapper-plugin.ts would resolve this.

Additional context

No response

Logs

TypeError: Cannot read properties of undefined (reading '_name')
 ❯ node_modules/@nuxt/test-utils/dist/runtime/shared/vue-wrapper-plugin.mjs:4:105
      2| const PLUGIN_NAME = "nuxt-test-utils";
      3| export function getVueWrapperPlugin() {
      4|   const installed = config.plugins.VueWrapper.installedPlugins.find(({ options: options2 }) => options2._name …
       |                                                                                                         ^
      5|   if (installed) return installed.options;
      6|   const options = createPluginOptions();
 ❯ getVueWrapperPlugin node_modules/@nuxt/test-utils/dist/runtime/shared/vue-wrapper-plugin.mjs:4:64
 ❯ setupNuxt node_modules/@nuxt/test-utils/dist/runtime/shared/nuxt.mjs:9:46
 ❯ node_modules/@nuxt/test-utils/dist/runtime/entry.mjs:4:3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions