Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebaseUrls runs before Sass variables are resolved #19196

Open
7 tasks done
DavidBiddle opened this issue Jan 13, 2025 · 0 comments
Open
7 tasks done

rebaseUrls runs before Sass variables are resolved #19196

DavidBiddle opened this issue Jan 13, 2025 · 0 comments
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@DavidBiddle
Copy link

Describe the bug

I'm importing sass from a package (govuk-frontend) which has a mixin to generate asset URLs.

When using the modern Sass API with Vite, and using an alias in the import path, I find that the assets don't build and I get an error message $govuk-fonts-path + $filename referenced in $govuk-fonts-path + $filename didn't resolve at build time, it will remain unchanged to be resolved at runtime.

When debugging, I can see that the rebaseUrls function is converting the url($govuk-fonts-path + $filename) from the mixin into url("$govuk-fonts-path + $filename"). This is unexpected, because the variables should be replaced with their values before the rebaseUrls function wraps them in quotes.

This doesn't happen if the package is imported using another importer:

  • The package is imported using Sass's NodePackageImporter and the pkg: syntax
  • The package is imported using its full node_modules URL (i.e. node_modules/govuk-frontend/dist/govuk/all) which I think must use Sass's builtin FileImporter

It alsl doesn't happen when using the legacy Sass API. This suggests to me that there's something different happening in makeModernScssWorker’s internalImporter that causes rebaseUrls to be run before the sass variables have been resolved.

Reproduction

https://github.com/DavidBiddle/vite-issue-test

Steps to reproduce

Run npm install and npx vite build
Check response for didn't resolve at build time, it will remain unchanged to be resolved at runtime message

System Info

System:
    OS: macOS 15.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.07 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.1/bin/npm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.2

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants