Skip to content

sassOptions additionalData not working as expected - "Can't find stylesheet to import." #85424

@qjstuart

Description

@qjstuart

Link to the code that reproduces this issue

https://github.com/qjstuart/nextjs-sass-issue

To Reproduce

  1. Start the applicaiton npm run dev
  2. You should be faced with the following error:
## Error Type
Build Error

## Error Message
Error evaluating Node.js code

## Build Output
./ui/TestComponent.module.scss
Error evaluating Node.js code
Error: Can't find stylesheet to import.
  ╷
1 │ @use "variables" as *;
  │ ^^^^^^^^^^^^^^^^^^^^^
  ╵
  ui/TestComponent.module.scss 1:1  root stylesheet
Caused by: Error: Can't find stylesheet to import.
  ╷
1 │ @use "variables" as *;
  │ ^^^^^^^^^^^^^^^^^^^^^
  ╵
  ui/TestComponent.module.scss 1:1  root stylesheet
    [at Object.wrapException (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:2292:47)]
    [at /Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:87606:25]
    [at _wrapJsFunctionForAsync_closure.$protected (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:4960:15)]
    [at _wrapJsFunctionForAsync_closure.call$2 (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:37968:12)]
    [at _awaitOnObject_closure.call$1 (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:37956:32)]
    [at Object._rootRunUnary (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:5378:18)]
    [at StaticClosure.<anonymous> (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:124712:16)]
    [at _CustomZone.runUnary$2$2 (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:39399:39)]
    [at _Future__propagateToListeners_handleValueCallback.call$0 (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:38457:51)]
    [at Object._Future__propagateToListeners (/Users/quentin/Code/nextjs-sass-issue/nextjs-sass-issue/node_modules/sass/sass.dart.js:5170:93)]

Import trace:
  Server Component:
    ./ui/TestComponent.module.scss
    ./ui/TestComponent.tsx
    ./app/page.tsx

Next.js version: 16.0.0 (Turbopack)

  1. Go into next.config.ts and comment out additionalData.
  2. Go into TestComponent.module.scss and modify the @use statement to use the absolute path to the variables directory on your machine.
  3. If you updated the @use statement with the correct absolute path, the error should go away, because sass can now access the $background variable.

Current vs. Expected behavior

I expected includePaths and additionalData to make the variables available inside my module files.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.19.4
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

CSS

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

next dev (local), next build (local), next start (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSSRelated to CSS.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions