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

Vite Plugin Does Not Work With Storybook Vite #16751

Open
mwood23 opened this issue Feb 22, 2025 · 8 comments
Open

Vite Plugin Does Not Work With Storybook Vite #16751

mwood23 opened this issue Feb 22, 2025 · 8 comments

Comments

@mwood23
Copy link

mwood23 commented Feb 22, 2025

What version of Tailwind CSS are you using?

4.0.7

What build tool (or framework if it abstracts the build tool) are you using?

Storybook Vite (8.5.8)

What version of Node.js are you using?

v22.12.0

What browser are you using?

N/A

What operating system are you using?

macOS

Describe your issue

Tried to integrate the Vite plugin with tailwind V4 in Storybook Vite (8.5.8) and hit this error:

SB_CORE-SERVER_0007 (MainFileEvaluationError): Storybook couldn't evaluate your .storybook/main.ts file.

Original error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/marcuswood/moonshot/platform/node_modules/@tailwindcss/vite/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:314:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:605:13)
    at resolveExports (node:internal/modules/cjs/loader:640:36)

Storybook config

import { StorybookConfig } from '@storybook/react-vite';
import tailwindcss from '@tailwindcss/vite';

const config: StorybookConfig = {
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  addons: ['@storybook/addon-essentials'],
  framework: '@storybook/react-vite',
  staticDirs: ['./public'],
  viteFinal: (config) => {
    config.plugins?.push(tailwindcss());

    return config;
  },
  core: {
    builder: '@storybook/builder-vite',
  },
};

export default config;

If I add this patch, everything works no problem:

diff --git a/package.json b/package.json
index b2ec5209a1ffc89586176fb2c1fec2f0577112a2..c906c6bf8025ab5cf59b63cfdf4443117b96c62e 100644
--- a/package.json
+++ b/package.json
@@ -20,7 +20,8 @@
   "exports": {
     ".": {
       "types": "./dist/index.d.mts",
-      "import": "./dist/index.mjs"
+      "import": "./dist/index.mjs",
+      "default": "./dist/index.mjs"
     }
   },
   "dependencies": {

Not sure why this is needed, I keep getting mixed up on the ESM stuff. Looks pretty harmless to add? Filing the issue in case other people run into it!

@Kaifuny
Copy link

Kaifuny commented Feb 23, 2025

When I add tailwindcss(), it throws an error:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '/Your/Project/Path/packages/ui/\x00/iframe.html'

@skratchdot
Copy link

4.0.7 works for me, but with 4.0.8 i see the same error as @Kaifuny when using storybook.

@unional
Copy link

unional commented Feb 23, 2025

Related discussion: #16451

@unional
Copy link

unional commented Feb 23, 2025

Regarding the origin error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/marcuswood/moonshot/platform/node_modules/@tailwindcss/vite/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:314:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:605:13)
    at resolveExports (node:internal/modules/cjs/loader:640:36)

I believe Storybook is still using the CJS API, thus the issue.

@unional
Copy link

unional commented Feb 24, 2025

FYI, currently, tailwindcss, storybook, and vitest is in a deadlock:

I'm using [email protected], because [email protected] causing tests in vitest not executed: storybookjs/storybook#30307

Update: for now, I get around this by:

@fnumatic
Copy link

fnumatic commented Feb 24, 2025

same issue here
tailwindcss 4.0.7 is working, 4.0.8 is not.
"Storybook is still using the CJS API" -> thats maybe the main problem

Storybook is still using the CJS API

@pcoterecollective
Copy link

Same error (Storybook 8.5.8, Vite 6.1.0):
Unhandled promise rejection: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string, Uint8Array, or URL without null bytes. Received '<project-path>/\x00/iframe.html'

@philipp-spiess
Copy link
Member

Seems like there are two different errors being talked about in this issue. Let's use #16785 for the "must be a string, Uint8Array, or URL without null bytes" error and keep this issue for the "No "exports" main defined in" one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants