Skip to content

Vite produces invalid output paths when rebasing URLs in SCSS files #19815

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

Open
7 tasks done
VasilyStrelyaev opened this issue Apr 8, 2025 · 0 comments
Open
7 tasks done

Comments

@VasilyStrelyaev
Copy link

Describe the bug

I have a Vite.js application where I import an SCSS file from a dependency. In a CSS bundle produce by Vite, the path is incorrect and invalid.

This issue seems to be specific to the file structure, as I can reproduce it if the SCSS file name matches the target directory name except the leading underscore and the url() argument is built using a variable:

├── foobar
│   └── static.png
└──  _foobar.scss // <- url("foobar/#{$file-name}.png")

In the resulting bundle, the foobar/static.png relative path is rebased to become .../xxx/_foobar.scssstatic.png (see the reproduction repo).

In the real life scenario, although we do control the said dependency, changes to its file structure constitute a breaking change for our customers, that is why it's important for us that this issue is addressed.

This issue may look a bit similar to the existing scss path rebase issues, both fixed and active (#11012, #19058), but I believe it may be a separate problem given that the open issues do not mention distorted file paths.

Reproduction

https://github.com/VasilyStrelyaev/vite-scss-path-rebase-repro

Steps to reproduce

  1. npm install
  2. npm run build to build a barebone app in packages/client-app
  3. Open the build output at packages/client-app/dist/assets/index-XXX.css
  4. Search for the url() function and notice its argument. Vite rebased the foobar/react.png relative path so that it became invalid: ../../scss-dep/src/_foobar.scssreact.png

System Info

System:
    OS: macOS 15.4
    CPU: (8) arm64 Apple M1 Pro
    Memory: 499.88 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/local/bin/node
    Yarn: 1.22.22 - ~/.yarn/bin/yarn
    npm: 11.2.0 - /usr/local/bin/npm
    pnpm: 9.15.4 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 135.0.7049.42
    Edge: 135.0.3179.54
    Safari: 18.4

Used Package Manager

npm

Logs

No response

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant