You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I followed manual install instructions from here with react-vite framework. The autoinstall script would not run for some reason using yarn dlx, could be something on my side.
When trying to run Storybook tests with Vitest, all tests fail with the following error:
A different, but similar error is shown when enabling the storybookScript option in the vitest plugin:
Error: Failed to load url <absolute/path/to/my/repo>/@storybook/experimental-addon-test/internal/global-setup (resolved id: <absolute/path/to/my/repo>/@storybook/experimental-addon-test/internal/global-setup). Does the file exist?
It seems Vite tries to resolve these modules as an absolute path and relative to my repository root instead of as an NPM module.
I think this might be related to the fact that I'm using Yarn pnpm. I had to do this getAbsolutePath trick before to make things work (see main.js below), could something similar be going on here?
import{storybookTest}from'@storybook/experimental-addon-test/vitest-plugin';import{defineConfig,mergeConfig}from'vitest/config';importviteConfigfrom'./vite.config';exportdefaultmergeConfig(viteConfig,defineConfig({plugins: [storybookTest({// storybookScript: 'yarn storybook --ci',}),],test: {exclude: ['**/*.pw.test.jsx','dist/**'],// Glob pattern to find story filesinclude: ['src/**/*.stories.?(m)[jt]s?(x)'],// Enable browser modebrowser: {enabled: true,name: 'chromium',// Make sure to install Playwrightprovider: 'playwright',headless: true,},// Speed up tests and better match how they run in Storybook itself// https://vitest.dev/config/#isolate// Consider removing this if you have flaky testsisolate: false,setupFiles: ['./vitest.setup.js'],},}),);
vitest.setup.js
import { setProjectAnnotations } from '@storybook/react';
import { beforeAll } from 'vitest';
import * as previewAnnotations from './.storybook/preview';
const annotations = setProjectAnnotations([previewAnnotations]);
// Run Storybook's beforeAll hook
beforeAll(annotations.beforeAll);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
I followed manual install instructions from here with react-vite framework. The autoinstall script would not run for some reason using
yarn dlx
, could be something on my side.When trying to run Storybook tests with Vitest, all tests fail with the following error:
Originates from this line of code
A different, but similar error is shown when enabling the
storybookScript
option in the vitest plugin:Originates from this line of code.
It seems Vite tries to resolve these modules as an absolute path and relative to my repository root instead of as an NPM module.
I think this might be related to the fact that I'm using Yarn pnpm. I had to do this
getAbsolutePath
trick before to make things work (see main.js below), could something similar be going on here?This is also mentioned in your FAQ.
I can run my Storybook with Vite perfectly fine.
framework:
react-vite
Storybook packages: 8.3.4
vite: 5.4.8
vitest: 2.1.1
Additional information
main.js
vitest.config.js
vitest.setup.js
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions