Skip to content

Setting css.modules.scopeBehaviour has no effect unless filename includes .module. #20929

@NoelAbrahams

Description

@NoelAbrahams

Describe the bug

The Problem

According to the docs, vite.config.ts → css.modules.scopeBehaviour is passed through to postcss-modules, which “assumes all classes are local by default” and allows users to override that behaviour.

However, in practice Vite only applies the CSS Modules transform to files whose names include the .module. infix (e.g. button.module.scss).

When the same file is renamed to button.scss, the transform is skipped entirely — the file is treated as global CSS — even if scopeBehaviour: 'local' is explicitly set.

This means the scopeBehaviour option is effectively ignored unless the filename matches the internal .module. regex in Vite’s CSS plugin.

Why this matters

In many modern component-based codebases the overwhelming majority of styles are written as CSS Modules — with perhaps a single global theme file. The .module suffix therefore becomes redundant in frameworks that assume “module by default”.

Reproduction

Requires multiple steps, hence not possible

Steps to reproduce

1 Create a Vite project.

Add this to vite.config.ts:

export default {
  css: {
    modules: { scopeBehaviour: 'local' }
  }
};

2 Create App.scss:

.foo { color: red; }

  1. Import it in App.tsx:
import styles from './App.scss';
console.log(styles);

Run vite.

System Info

Browser error
The requested module '/src/App.scss' does not provide an export named 'default'.

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions