storybook: [Bug]: /virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files

Describe the bug

When starting or building Storybook in a Vite project, the following lines are logged to the terminal:

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files

In Vite 4 projects, even more files might be affected.

Reproduction steps

  1. Initialize Storybook in a Vite Project
  2. Start Storybook

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 54
  • Comments: 31 (8 by maintainers)

Most upvoted comments

Any update on this?

I use storybook 8.2.7 with a new react (with vite) project and it also appears to me:

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files

+1 storybook v8.2.9, vite + react

Still an issue, v8.2.9

 | Storybook 8.2.9 for preact-vite started
 ...
 | Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files
 | Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
 | Sourcemap for "project-name/node_modules/.cache/storybook/cea5d5a57c0bd9ff1b61587365bbdefc908c69a21e9c90584eadf79edbb4a529/sb-vite/deps/chunk-NKYJLOIU.js" points to missing source files
 | Sourcemap for "project-name/node_modules/.cache/storybook/cea5d5a57c0bd9ff1b61587365bbdefc908c69a21e9c90584eadf79edbb4a529/sb-vite/deps/chunk-LUT37SML.js" points to missing source files
 | Sourcemap for "project-name/node_modules/.cache/storybook/cea5d5a57c0bd9ff1b61587365bbdefc908c69a21e9c90584eadf79edbb4a529/sb-vite/deps/chunk-YGRMY5AF.js" points to missing source files
 | Sourcemap for "project-name/node_modules/.cache/storybook/cea5d5a57c0bd9ff1b61587365bbdefc908c69a21e9c90584eadf79edbb4a529/sb-vite/deps/chunk-JNHMQTSP.js" points to missing source files
 | Sourcemap for "project-name/node_modules/.cache/storybook/cea5d5a57c0bd9ff1b61587365bbdefc908c69a21e9c90584eadf79edbb4a529/sb-vite/deps/chunk-KY3SZA6T.js" points to missing source files

I’m getting the same errors, with Storybook 8.2.7 (+ vite):

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files

Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-JT2S5XWW.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-G4IBRLZB.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-Q3AQ5QX7.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-H34TB425.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-JO3NLJMA.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-IMALHOV3.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-G2BJXQAJ.js" points to missing source files
Sourcemap for "project-name/node_modules/.cache/storybook/1c3385a5d25e538d10b518b310c74d3ca2690b6aaffeadccd74da79736171f86/sb-vite/deps/chunk-LPRKOUG3.js" points to missing source files

Thanks for sorting this out 🥳

Not yet! I can investigate it next week as part of my empathy week!

I can confirm that with version 8.3.0 this issue no more exists.

I can confirm that issue still persist with storybook v8.2.9 and Vite + react.

Yes, the fix of the issue was reverted, and it’s still in progress for the next 8.3 : https://github.com/storybookjs/storybook/pull/28867

I also am experiencing:

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files

In addition, HMR is not working. I am on Vite 5.3.5, storybook 8.2.7 (in react).

I was facing the same issue today after upgrading to 8.2.4 Sourcemap for “/virtual:/@storybook/builder-vite/setup-addons.js” points to missing source files Sourcemap for “/virtual:/@storybook/builder-vite/vite-app.js” points to missing source files

So Ive downgraded back to 7.6.20

Tested in 8.3.0-beta.0 and still seeing this issue

I encountered the same logs. Meanwhile I guess downgrading is the fix. Note: Handle storybooks/addons versions for compatibility, I made them match 8.1.11 storybook version.

    "storybook": "8.1.11",
    "@storybook/addon-essentials": "8.1.11"
    "@storybook/addon-interactions": "8.1.11",
    "@storybook/addon-links": "8.1.11",
    "@storybook/blocks": "8.1.11",
    "@storybook/builder-vite": "8.1.11",
    "@storybook/manager-api": "8.1.11",
    "@storybook/react": "8.1.11",
    "@storybook/react-vite": "8.1.11",
    "@storybook/test": "8.1.11",
    "@storybook/theming": "8.1.11"
    
    

@David05500 Except of having a nasty warning in the terminal Storybook should still function. I wouldn’t recommend to downgrade just because of it. You could upgrade to 8.1.11. This version is not containing the issue.

Upgraded from 8.0.4 to 8.2.4 today and am now running into this issue.

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files
Sourcemap for "/Users/kerry/dev/some-design-worktree/components/projects/components/node_modules/.cache/storybook/c698b8ade20774e74879ccaec4f97d28db2fdf6f7fb93649c7d24018c42360de/sb-vite/deps/chunk-4UF4PDC3.js" points to missing source files

…and so on

@valentinpalkovic believes the docs error I'm facing inside here has no relation to missing source files, so de-emphasizing it here I am guessing this is what's causing my `parameters.docs.source.transform`'s `code` parameter to be undefined and basically error out with the following in any of my component's docs page:

capture-2024-07-15-xxQUTgge

** Disclaimer** This information might be inaccurate, due to it being generated automatically To resolve the issue with missing source files in sourcemaps for /virtual:/@storybook/builder-vite/setup-addons.js and /virtual:/@storybook/builder-vite/vite-app.js, follow these steps:

  1. Check Vite Configuration: Ensure that the Vite configuration in vite-config.ts includes proper handling for source maps.
// vite-config.ts
export async function commonConfig(options: Options, _type: PluginConfigType): Promise<ViteInlineConfig> {
  const configEnv = _type === 'development' ? configEnvServe : configEnvBuild;
  const { loadConfigFromFile, mergeConfig } = await import('vite');

  const { viteConfigPath } = await getBuilderOptions<BuilderOptions>(options);
  const projectRoot = path.resolve(options.configDir, '..');

  const { config: { build: buildProperty = undefined, ...userConfig } = {} } =
    (await loadConfigFromFile(configEnv, viteConfigPath, projectRoot)) ?? {};

  const sbConfig: InlineConfig = {
    configFile: false,
    cacheDir: resolvePathInStorybookCache('sb-vite', options.cacheKey),
    root: projectRoot,
    base: './',
    plugins: await pluginConfig(options),
    resolve: {
      conditions: ['storybook', 'stories', 'test', 'browser', 'import', 'module', 'default'],
      preserveSymlinks: isPreservingSymlinks(),
      alias: {
        assert: require.resolve('browser-assert'),
      },
    },
    envPrefix: userConfig.envPrefix ? ['STORYBOOK_'] : ['VITE_', 'STORYBOOK_'],
    build: {
      target: buildProperty?.target,
      sourcemap: true, // Ensure sourcemap is enabled
    },
  };

  const config: ViteConfig = mergeConfig(userConfig, sbConfig);

  return config;
}
  1. Verify Plugin Setup: Ensure that the plugins used in pluginConfig handle source maps correctly.
// vite-config.ts
export async function pluginConfig(options: Options) {
  const frameworkName = await getFrameworkName(options);
  const build = await options.presets.apply('build');

  const externals: Record<string, string> = globalsNameReferenceMap;

  if (build?.test?.disableBlocks) {
    externals['@storybook/blocks'] = '__STORYBOOK_BLOCKS_EMPTY_MODULE__';
  }

  const plugins = [
    codeGeneratorPlugin(options),
    await csfPlugin(options),
    await injectExportOrderPlugin(),
    await stripStoryHMRBoundary(),
    {
      name: 'storybook:allow-storybook-dir',
      enforce: 'post',
      config(config) {
        if (config?.server?.fs?.allow) {
          config.server.fs.allow.push('.storybook');
        }
      },
    },
    await externalGlobalsPlugin(externals),
    pluginWebpackStats({ workingDir: process.cwd() }),
  ] as PluginOption[];

  if (frameworkName === '@storybook/glimmerx-vite') {
    const plugin = require('vite-plugin-glimmerx/index.cjs');
    plugins.push(plugin.default());
  }

  return plugins;
}
  1. Update index.ts: Ensure that the Vite server is correctly configured to handle source maps.
// index.ts
export const start: ViteBuilder['start'] = async ({ startTime, options, router, server: devServer }) => {
  server = await createViteServer(options as Options, devServer);

  const previewResolvedDir = join(corePath, 'dist/preview');
  const previewDirOrigin = previewResolvedDir;

  router.use(`/sb-preview`, express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));
  router.use(iframeMiddleware(options as Options, server));
  router.use(server.middlewares);

  return {
    bail,
    stats: {
      toJson: () => {
        throw new NoStatsForViteDevError();
      },
    },
    totalTime: process.hrtime(startTime),
  };
};

These changes should ensure that the source maps are correctly generated and point to the correct source files.

References

/code/builders/builder-vite/src/index.ts /code/builders/builder-vite/src/vite-config.ts /code/builders/builder-vite /code/builders

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

I’m experiencing the same issue with Storybook 8.2.9, too.

BTW: I created a sandbox project with the Storybook CLI (npx storybook@8.2.7 sandbox vue).

When I start the storybook instance in this new and clean project, even then I get the following errors:

Sourcemap for "/virtual:/@storybook/builder-vite/setup-addons.js" points to missing source files
Sourcemap for "/virtual:/@storybook/builder-vite/vite-app.js" points to missing source files

I can confirm this bug in a Vue + Vite + Storybook project. I just upgraded to Storybook 8.2.7 from Storybook 7.

I have similar issue as @phamhongphuc on Yarn 4 PnP and Storybook Vite 8.2.5. It seems deleting .yarn.lock file, deleting the .cache folder, and reinstalling with yarn resolved the issue. Probably since the lock file still had older vite versions which were missing patches.

For the virtual modules, there is forward slash (/) before :virtual, but the filter regex in vite doesn’t have a pattern to match.

// Virtual modules should be prefixed with a null byte to avoid a
// false positive "missing source" warning. We also check for certain
// prefixes used for special handling in esbuildDepPlugin.
const virtualSourceRE = /^(?:dep:|browser-external:|virtual:)|\0/

Is there a reason why source maps are generated for @storybook modules? I believe we can turn off loading source maps, but doesn’t seem to be preventable when modules already have source maps.

I can confirm that issue still persist with storybook v8.2.9 and Vite + react.

Does anyone else here have problem with autodocs not shoing up the table for props, emits and so on? I’m starting to think that this warning in the console has something to do with autodocs pages bascially being empty. Only the args that I define for a story are shown as well as their controls. But If I don’t define any args explicitly, the autodocs page is basically empty and thus uselesse.

@Walnussbaer For me, it’s not related to this issue.

Try with the version 8.1 of storybook, if you have also the autodocs problem, looks at the new vue docgen option in >= 8.0 : https://storybook.js.org/docs/get-started/frameworks/vue3-vite?renderer=vue#using-vue-component-meta

    options: {
+      docgen: 'vue-component-meta',
    },

I downgraded to 8.1.11 but still no meaningful autodocs page (I was already using vue-component-meta). I can see the component but the controls are still missing. I will open my own bug ticket, because I don’t want to conquer this one here. Thanks anyway for your suggestion to try 8.1 😃

Same for me, while upgrading to 8.2.7 (react + vite):

image Please advise.

This looks more like a different bug.

Except of having a nasty warning in the terminal Storybook should still function.

I don’t see any functional issues even though the warning appears in the terminal.

Has anyone encountered any actual failures anywhere?

My deps now:

"@storybook/addon-a11y": "^8.2.5",
"@storybook/addon-docs": "^8.2.5",
"@storybook/addon-essentials": "^8.2.5",
"@storybook/addon-interactions": "^8.2.5",
"@storybook/addon-links": "^8.2.5",
"@storybook/react": "^8.2.5",
"@storybook/react-vite": "^8.2.5",
"@storybook/test": "^8.2.5",
"@storybook/test-runner": "^0.19.1",
"storybook": "^8.2.5",