-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Issue with Vite's new Sass JS API and @blakedarlin/sass-json-importer
#18961
Comments
Can you move your reproduction somewhere else? It now says "Out of credits". |
Hello @Nathan7139. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
Sorry about that, I assumed you would fork a copy to run it directly. Here’s another link to the reproduction: New Link. The reason I’m not using StackBlitz is that it seems to have issues with Let me know if you encounter any issues with this new link! |
I simplified a repro https://stackblitz.com/edit/vitejs-vite-nhtz78vk?file=src%2Ftest.scss (again this needs to be downloaded and run locally for sass-embedded) I haven't dug deeper, but it looks like user's custom importer is not kicking in when the file is loaded via Vite's internal custom importer (in this case // [working]
@import './scss/colors.scss';
// [not working]
@import "@/scss/colors.scss"; |
The custom importer order does't look intuitive, but I'd assume sass spec says so somewhere. Probably we should check with them too.
For Vite side, considering we check extension on vite/packages/vite/src/node/plugins/css.ts Lines 2379 to 2386 in 63b82f1
|
It sounds like some implementations in Vite caused the custom importer not to work correctly. Am I understanding this correctly? Thank you for the fix and the quick response! |
Describe the bug
Describe the bug
I'm attempting to use Vite's new Sass JS API for a project where I need to convert JSON files into Sass variables. Previously, I used the
node-sass-json-importer
package with the old Vite configuration. Here's an example of the old config:With the new API, I switched to using
@blakedarlin/sass-json-importer
. Below is my updated Vite config:However, the
@blakedarlin/sass-json-importer
package doesn't work as expected in the Vite environment. When I print out theurl
from thecanonicalize
method, it always returns@BBB/assets/scss/utils
. This is problematic becauseutils/index.scss
is not a JSON file, andcanonicalize
returnsnull
. Oncecanonicalize
returnsnull
, other@use
,@forward
, or@import
statements insideutils/index.scss
are skipped by this importer and are only processed by the default importer.I confirmed that this package is designed to work specifically with
sass-embedded
. I also raised this issue in the Sass community, and the conclusion was that Sass itself seems to process the input correctly, so this might be a Vite-related issue.Reproduction
https://codesandbox.io/p/devbox/k8xtqw?file=%2Fvite.config.js
(or as zip to download vite-18961-sass-json.zip)
Steps to reproduce
pnpm install && pnpm dev
in the example project.vite.config.js
file also usessass.compileAsync
to compileindex.scss
.sass.compileAsync
, everything works fine, and the console output shows:utils/index.scss
, and the importer doesn't process JSON correctly aftercanonicalize
returnsnull
.sass.compileAsync
appears to handle everything correctly, so this seems to be specific to Vite's handling of the Sass API.Is this issue related to Vite's Sass integration, the way I'm using the
@blakedarlin/sass-json-importer
, or the implementation of the package itself?Any guidance or recommendations would be appreciated!
Thanks in advance for your support!
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: