Common Issues
Find solutions to the most common problems when using styled-static.Storybook: 'This package is ESM only' error
Storybook: 'This package is ESM only' error
If you see this error when using styled-static with Storybook:Solution: Add the package to Vite’s This is a known limitation with ESM-only packages in Storybook’s esbuild-based config loading.
optimizeDeps.include in your Storybook config:.storybook/main.ts
Plugin not transforming code
Plugin not transforming code
If you see an error like:Solution: Ensure the styled-static plugin is configured correctly in
vite.config.ts:vite.config.ts
Styles not appearing in production
Styles not appearing in production
If your styles work in development but disappear in production builds:Solution: Check that:
- Your build process is completing successfully
- CSS files are being generated in the
distfolder - Your HTML file is loading the generated CSS
TypeScript errors with styled components
TypeScript errors with styled components
If you’re seeing TypeScript errors when using styled components:Solution: Ensure you have proper type definitions installed:The library provides full TypeScript support out of the box. If you’re extending styled components with custom props, make sure to properly type them:
CSS nesting not working
CSS nesting not working
If CSS nesting syntax is not working in your styles:Solution: styled-static uses native CSS nesting, which is supported in all modern browsers:
- Chrome 112+
- Safari 16.5+
- Firefox 117+
- Edge 112+
vite.config.ts
Hot Module Replacement (HMR) not working
Hot Module Replacement (HMR) not working
If style changes don’t update immediately during development:Solution: This is usually caused by:
- Browser caching: Try a hard refresh (Ctrl+Shift+R or Cmd+Shift+R)
- Plugin order: Ensure
styledStatic()comes beforereact()in your Vite config - File watching: Check that your file isn’t being ignored by Vite’s watcher
Class names are too long in development
Class names are too long in development
In development mode, styled-static generates readable class names like
ss-Button-MyComponent.This is intentional for better debugging. In production builds, class names are automatically hashed to minimal sizes like ss-abc123 for optimal performance.If you want to customize the prefix, use the classPrefix option:vite.config.ts
Getting Help
If you’re still experiencing issues:GitHub Issues
Report bugs or request features on GitHub
Source Code
View the source code and implementation details