You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importjsonImporterfrom'node-sass-json-importer';exportdefault{css: {preprocessorOptions: {scss: {additionalData: '@use "@BBB/assets/scss/utils" as *;',importer: jsonImporter(),},},// Specific PostCSS config file folder.postcss: '../../packages/AAA',},};
With the new API, I switched to using @blakedarlin/sass-json-importer. Below is my updated Vite config:
importjsonImporterfrom'@blakedarlin/sass-json-importer';exportdefault{css: {preprocessorOptions: {scss: {api: 'modern-compiler',additionalData: '@use "@BBB/assets/scss/utils" as *;',importers: [jsonImporter()],silenceDeprecations: ['mixed-decls','import'],},},// Specific PostCSS config file folder.postcss: '../../packages/AAA',},};
However, the @blakedarlin/sass-json-importer package doesn't work as expected in the Vite environment. When I print out the url from the canonicalize method, it always returns @BBB/assets/scss/utils. This is problematic because utils/index.scss is not a JSON file, and canonicalize returns null. Once canonicalize returns null, other @use, @forward, or @import statements inside utils/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.
The issue occurs when Vite tries to handle imports within utils/index.scss, and the importer doesn't process JSON correctly after canonicalize returns null.
The standalone 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!
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
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
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: