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
When importing .module.scss files directly from a dependency package (in my reproduction case @acme/ui is the "external" package, but you could imagine any dependency instead) in a Vite project, the imports work correctly in development mode but none of the styles are applied/compiled during production build. This does not work both when importing a module from another module scss file or directly from the application code.
SCSS Modules imports from workspace packages should work consistently in both development and production builds even when deeply imported from dependency
Styles should be properly processed and included in the final bundle
Actual Behavior
Development mode (pnpm dev): CSS Modules imports work correctly
Production build (pnpm build): Build does not apply styles with module resolution errors for deep imports of .module.scss files from node modules
Environment
Vite: 6.0.1 (IMPORTANT: Also not working in 5.4.10)
Node.js: 20.18
OS: MacOS Latest
Package Manager: pnpm (also appears using npm, yarn)
Additional Context
This issue appears to be related to how Vite handles CSS Modules imports from node_modules during production builds. While the development server can resolve these imports through the workspace, the production build seems to have different module resolution rules.
Would appreciate guidance on the recommended approach to handle SCSS Modules imports from both workspace packages and dependencies in Vite projects.
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
Description
When importing
.module.scss
files directly from a dependency package (in my reproduction case@acme/ui
is the "external" package, but you could imagine any dependency instead) in a Vite project, the imports work correctly in development mode but none of the styles are applied/compiled during production build. This does not work both when importing a module from another module scss file or directly from the application code.Reproduction
Project structure:
Code Examples
Expected Behavior
Actual Behavior
pnpm dev
): CSS Modules imports work correctlypnpm build
): Build does not apply styles with module resolution errors for deep imports of.module.scss
files from node modulesEnvironment
Additional Context
This issue appears to be related to how Vite handles CSS Modules imports from node_modules during production builds. While the development server can resolve these imports through the workspace, the production build seems to have different module resolution rules.
Would appreciate guidance on the recommended approach to handle SCSS Modules imports from both workspace packages and dependencies in Vite projects.
Reproduction
https://github.com/moishinetzer/vite-scss-modules-reproduction
Steps to reproduce
Compare
pnpm dev
withpnpm build
System Info
Used Package Manager
pnpm
Logs
VITE v6.0.3 ready in 115 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
More info: https://sass-lang.com/d/legacy-js-api
Validations
The text was updated successfully, but these errors were encountered: