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

Node modules SCSS imports not resolved properly in nested path #15283

Closed
7 tasks done
zaalbarxx opened this issue Dec 7, 2023 · 5 comments
Closed
7 tasks done

Node modules SCSS imports not resolved properly in nested path #15283

zaalbarxx opened this issue Dec 7, 2023 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@zaalbarxx
Copy link

Describe the bug

Like in stackblitz, we noticed that there is some issue with imports from external packages if "root" SCSS file which imports 3rd party styles is not located in the root directory.
If you move the main.scss file into root directory like here:
https://stackblitz.com/edit/vue3-vite-starter-r4t51x?file=package.json,src%2FApp.vue,src%2Fmain.js
the error goes away and everything works.

The issue here seem to be that for some reason when "root" SCSS file is inside app/styles directory then it tries to resolve the path like for example app/styles/v-calendar, but when you move the main.scss into root directory then it will remove this app/styles goes away and then it assumes it is the node module and correctly resolve it from there.

Not sure if this is related to Vite and it's CSS/SASS plugin itself or maybe it is related to Vue plugin (importing SASS file from script block or JS file seem to correctly import and process the SCSS file). It's worth noting that not every package has this problem (kinda weird, some of other packages do not report this error even though they also have the correct "exports" field in package.json)

Reproduction

https://stackblitz.com/edit/vue3-vite-starter-wmnist?file=package.json,src%2FApp.vue,src%2Fmain.js,vite.config.js

Steps to reproduce

Go to stackblitz and check the console

System Info

windows 11, vite 5.0.6

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Dec 7, 2023

@zaalbarxx
Copy link
Author

zaalbarxx commented Dec 7, 2023

After some investigation I found that this is related to this code which supposedly "rebases" URLs in the imported file
image
It looks like the path then is "rebased" from "v-calendar/style.css" to "styles/v-calenda/style.css", and then Dart SASS is not able to further resolve the file. The workaround is to either:

  • @import './styles/main' in App.vue (instead of importing using alias like @import '@/styles/main', this way it seems that "rebasing" logic is not being triggered
  • move the main.scss file to the root of the project (src/ directory)

Either way I think this is a buggy behavior, isn't it ?
Cheers

@sapphi-red
Copy link
Member

Duplicate of #12227

@sapphi-red sapphi-red marked this as a duplicate of #12227 Dec 9, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Dec 9, 2023
@zaalbarxx
Copy link
Author

@sapphi-red While I believe this is a minor bug, I don't think it is the same case as the one you marked as duplicate of this. Here there is no issue with node module's style transively importing other style since we are importing CSS file.

@sapphi-red
Copy link
Member

I believe the underlying problem is same and will be fixed by #15000.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants