fix(sass): include node_modules in Dart Sass loadPaths to fix Windows @import resolution#93842
Open
creazyfrog wants to merge 1 commit into
Open
Conversation
…import resolution On Windows, the sass-loader webpack importer loses path context when resolving relative @import statements inside node_modules packages (e.g. @import './themes/light.scss' inside @primer/css). The importer returns null, and Dart Sass's built-in resolver also fails because node_modules is not in its loadPaths. Fix: prepend <rootDirectory>/node_modules to the Dart Sass loadPaths option so the native resolver can always find package files. User- specified loadPaths are preserved and appended after the default. Fixes vercel#93583. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #93583.
On Windows (native, no WSL),
sass-loaderwith the modern Dart Sass API fails to resolve relative@importstatements insidenode_modulespackages. For example,@primer/css/color-modes/index.scssdoes@import './themes/light.scss', and the build fails with:Root cause
When the sass-loader webpack importer (
webpackImporter: true, the default) can't resolve the path on Windows due to backslash/forward-slash path separator differences, it returnsnull. Dart Sass then falls back to its built-in resolver, but that resolver only searches the file's own directory and user-specifiedloadPaths. Sincenode_modulesis not inloadPathsby default, the relative import inside the package fails.Fix
In
packages/next/src/build/webpack/config/blocks/css/index.ts, prepend<rootDirectory>/node_modulesto theloadPathsoption passed to sass-loader. This ensures Dart Sass can always resolve package imports natively, regardless of whether the webpack importer succeeds.User-specified
sassOptions.loadPathsvalues are preserved and appended after the default, so there is no breaking change.Why this is safe
loadPathsfor resolving packages fromnode_modulesloadPathsvalues take precedence (appended after the default) and continue to work unchangedTest plan
npm install && npm run dev— build should succeed without SCSS import errorssassOptions.loadPathsvalues should still work🤖 Generated with Claude Code