fix(sass): add sassOptions loadPaths to resolve SCSS partials via @/ alias - #51
Merged
Conversation
When a CSS Module uses @use "@/styles/mixins" (the @/ path alias), resolve-url-loader strips the file-system working directory from Dart Sass's compilation context. This causes @forward "tables" and sibling bare imports inside _index.scss to fail with 'Can't find stylesheet to import' even though the files exist. Adding sassOptions.loadPaths (Turbopack/modern Dart Sass) and includePaths (webpack sass-loader) pointing to src/styles and src/styles/mixins gives Dart Sass explicit search paths that survive the lost context, fixing the build without modifying any SCSS source files. Reproduces on: Next.js 16.3.0, Dart Sass 1.102.0, Windows (pnpm)
RsbhThakur
approved these changes
Sep 5, 2026
RsbhThakur
left a comment
Contributor
There was a problem hiding this comment.
Tested in local, Looks Good To Me!
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
When a CSS Module uses
@use "@/styles/mixins"(the@/path alias instead of a relative../../path),resolve-url-loaderstrips the file-system working directory from Dart Sass's compilation context. This causes@forward "tables"and all sibling bare imports inside_index.scssto fail:This was introduced in commit
65541597whereLinkCard.module.scssadded@use "@/styles/mixins" as *— the first component file to use the@/alias for the mixin barrel rather than a relative path.Root Cause
The loader chain for SCSS modules includes
resolve-url-loader→sass-loader. Whenresolve-url-loaderprocesses a file loaded via a webpack alias (@/styles/mixins), it does not preserve the file-system working directory for Dart Sass. As a result, Dart Sass has no anchor point to resolve@forward "tables"or@forward "./tables"— both fail equally since the directory context is gone.All other CSS Modules in the project use real relative paths (e.g.
@use "../../../../styles/mixins" as *) and are unaffected.Fix
Added
sassOptionstonext.config.mjswith explicit load paths:loadPaths— picked up by Turbopack / modern Dart SassincludePaths— picked up by webpack'ssass-loaderThis gives Dart Sass fallback search paths that survive the stripped context. No SCSS source files were modified.
Verification
65541597(500 on/internal/dashboardand other routes)