Skip to content

[Bug]: vue-component-meta plugin ReferenceError when export name is a substring of barrel re-export path #34521

@mspostolov

Description

@mspostolov

Describe the bug

When using vue-component-meta docgen with barrel files that use export * from './...', the plugin generates ReferenceError: <Name> is not defined if an exported component name is a substring of a re-export path.

For example, if a barrel has export * from './Tabs' and the Tabs module exports both Tabs and Tab, the plugin incorrectly appends Tab.__docgenInfo = ... to the barrel file — but Tab is not a local variable there.

Root cause

In the plugin's transform function (@storybook/vue3-vite/dist/preset.js), the check that decides whether to append __docgenInfo uses src.includes(name):

  new RegExp(`export {.*${name}.*}`).test(src)                                                                                                                                     
  || new RegExp(`export \\* from ['"]\\S*${name}['"]`).test(src)                                                                                                                     
  || !src.includes(name)                                                                                                                                                             
  || (/* append: name.__docgenInfo = ... */)                                                                                                                                         

src.includes('Tab') matches 'Tab' as a substring inside export * from './Tabs', so the plugin appends Tab.__docgenInfo = ... even though Tab is not a local binding in the barrel.

Reproduction link

https://github.com/mspostolov/storybook-vue-component-meta-barrel-bug

Reproduction steps

  git clone https://github.com/mspostolov/storybook-vue-component-meta-barrel-bug.git
  cd storybook-vue-component-meta-barrel-bug                                                                                                                                         
  npm install                                                                                                                                                                      
  npm run storybook

Open browser console:

  ReferenceError: Tab is not defined                                                                                                                                                 
      at index.ts:4:15                                                                                                                                                             

StackBlitz: https://stackblitz.com/github/mspostolov/storybook-vue-component-meta-barrel-bug

Expected behavior

The plugin should not append __docgenInfo for names that are only substring-matched in barrel re-export paths. The src.includes(name) check should use word-boundary matching or verify that the name exists as an actual local binding.

System

Storybook Environment Info:
│
│  System:
│  OS: macOS 15.5
│  CPU: (10) arm64 Apple M1 Pro
│  Shell: 5.9 - /bin/zsh
│  Binaries:
│  Node: 24.13.0
│  npm: 11.6.2
│  active
│  pnpm: 10.28.0
│  Browsers:
│  Chrome: 146.0.7680.178
│  npmPackages:
│  @storybook/addon-docs: ^10.3.0 => 10.3.5
│  @storybook/vue3-vite: ^10.3.0 => 10.3.5
│  storybook: ^10.3.0 => 10.3.5

Additional context

No response

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