Skip to content

[Bug] Windows: sass-loader fails to resolve SCSS imports from node_modules in webpack mode (not Turbopack) #93583

@anarefolio

Description

@anarefolio

Link to the code that reproduces this issue

https://github.com/anarefolio/docs

To Reproduce

  1. Windows 10/11, Node.js 24, native (no WSL)
  2. Clone https://github.com/github/docs
  3. Run npm install
  4. Run npm run dev
  5. Open browser at localhost:4000

Result: Error: Can't find stylesheet to import.
@import './themes/light.scss'
node_modules@primer\css\color-modes\index.scss

Root cause: Next.js bundled sass-loader defaults to legacy API
with webpackImporter:true, which loses path context on Windows when
resolving SCSS imports inside node_modules.

Workaround found and documented here:
github/docs#44118

The fix requires patching next/dist/compiled/sass-loader/cjs.js to:

  1. Use modern-compiler API instead of legacy
  2. Set webpackImporter default to false
  3. Add node_modules to loadPaths

Current vs. Expected behavior

Current: Running npm run dev on Windows native (no WSL) fails immediately with:

Error: Can't find stylesheet to import.
@import './themes/light.scss'
node_modules@primer\css\color-modes\index.scss

Expected: SCSS imports from node_modules resolve correctly on Windows,
as they do on Linux/macOS. The contributing guide for github/docs explicitly
states "This site can be developed on Windows" but it cannot.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 16070
  Available CPU cores: 12
Binaries:
  Node: 24.15.0
  npm: 11.12.1
Relevant Packages:
  next: 16.2.3
  react: 19.2.5
  react-dom: 19.2.5
  typescript: 6.0.2

Which area(s) are affected? (Select all that apply)

CSS

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Note: Tested on next@16.2.3. The workaround documented in
github/docs#44118 confirms the root cause is in the compiled
sass-loader configuration, not version-specific.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSRelated to CSS.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions