✦ Continue with Google
AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js Fails To Resolve SCSS Imports From Node_modules On Windows In Webpack Mode Due To Legacy Sass-Loader Defaults

On Windows, Next.js 16.2.3 using webpack (non-Turbopack) with SCSS cannot resolve imports from node_modules, throwing 'Can't find stylesheet to import.' The bundled sass-loader is configured with the legacy API and webpackImporter enabled, which mishandles Windows path resolution. A workaround requires patching the compiled sass-loader to use the modern-compiler API, disable webpackImporter, and add node_modules to load paths.

highConfidence 95%Next.jsAffected V16.2.3

Origin Analysis

Next.js's internal sass-loader configuration for webpack sets `api: 'legacy'` and `webpackImporter: true`. The legacy API combined with webpackImporter loses path context on Windows when resolving SCSS imports located inside node_modules, causing import failure. This is a design flaw in how Next.js packages and configures sass-loader for cross-platform compatibility.
1. On Windows 10/11 with Node.js 24 (native, no WSL), clone the repository that uses SCSS imports from node_modules (e.g., github/docs). 2. Run `npm install`. 3. Run `npm run dev` (or `next dev`). 4. Observe error: 'Error: Can't find stylesheet to import. @import './themes/light.scss' node_modules\@primer\css\color-modes\index.scss'.

Fixing Code Block

Edge Case Audit

This patch modifies files inside node_modules, which will be overwritten on the next `npm install` or `yarn install`. To make it persistent, use a tool like patch-package or a postinstall script. The change to modern-compiler API may require Sass version >=1.45.0; older projects may need to upgrade. Disabling webpackImporter could affect projects that rely on webpack-specific import resolution (e.g., aliases or custom resolvers), so test on all target platforms. Adding node_modules to loadPaths might unintentionally expose all node_modules SCSS files to compilation. Rollback: restore the backup file (cjs.js.bak) or reinstall the package. This patch has been tested only for the reported use case; other configurations may behave differently.

Ecosystem Topology