Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] :Storybook + vite shows "No Preview" but story still renders below #26993

Open
1 task
dankurfirst opened this issue Apr 29, 2024 · 0 comments
Open
1 task
Labels

Comments

@dankurfirst
Copy link

What version of vite are you using?

5.2.10

System info and storybook versions

Storybook Environment Info:

System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Max
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/Library/Caches/fnm_multishells/49376_1714407388493/bin/node
Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/47960_1714407276778/bin/yarn
npm: 10.1.0 - ~/Library/Caches/fnm_multishells/49376_1714407388493/bin/npm <----- active
pnpm: 8.6.0 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 124.0.6367.91
Safari: 16.4
npmPackages:
@storybook/addon-essentials: ^8.0.9 => 8.0.9
@storybook/addon-interactions: ^8.0.9 => 8.0.9
@storybook/addon-links: ^8.0.9 => 8.0.9
@storybook/addon-onboarding: ^8.0.9 => 8.0.9
@storybook/blocks: ^8.0.9 => 8.0.9
@storybook/react: ^8.0.9 => 8.0.9
@storybook/react-vite: ^8.0.9 => 8.0.9
@storybook/test: ^8.0.9 => 8.0.9
eslint-plugin-storybook: ^0.8.0 => 0.8.0
storybook: ^8.0.9 => 8.0.9

Describe the Bug

After migrating from CRA to vite, all stories show a "No preview Available" message above the rendered story, as in the screenshot.

Screenshot 2024-04-29 at 2 48 50 PM

./storybook/main.ts

import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
	stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],

	addons: [
		'@storybook/addon-links',
		'@storybook/addon-essentials',
		'@storybook/addon-a11y',
		'@storybook/addon-jest',
		'@chromatic-com/storybook'
	],
	framework: {
		name: '@storybook/react-vite',
		options: {}
	},
	docs: {
		autodocs: true
	
}
}

export default config;

/./storybook/preview.ts

import type { Preview } from "@storybook/react";

const preview: Preview = {
  parameters: {
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
  },
};

export default preview;


vite.config.js


import react from '@vitejs/plugin-react-swc';
import path from 'path';
import { defineConfig } from 'vitest/config';
import svgrPlugin from 'vite-plugin-svgr';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import { globSync } from 'glob';
import commonjs from 'vite-plugin-commonjs'

export default defineConfig(({ mode }) => ({
	plugins: [react(), viteTsconfigPaths(), svgrPlugin(), commonjs()],
	build: {
		commonjsOptions: { transformMixedEsModules: true },
		cssCodeSplit: true,
		lib: { 
			entry: [...globSync('./src/**/*.entrypoint.tsx')],
			formats: ['es'],
		},
		outDir: '../react-frontend/build',
		manifest: true,
	},
	resolve: {
		alias: {
			lib: path.resolve(__dirname, './src/lib'),
		},
	},
	test: {
		globals: true,
		environment: 'jsdom',
		setupFiles: ['./vitest-setup.ts']
	},
	define: {
		'process.env': JSON.stringify({ 
			...import.meta.env,
			NODE_ENV: mode,
		}),
	},
}));

Link to Minimal Reproducible Example

No response

Participation

  • I am willing to submit a pull request for this issue.
@IanVS IanVS transferred this issue from storybookjs/builder-vite Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant