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
using @include in CSS will cause classes to be an empty object #146
Comments
I am facing a similar issue. It returns an error My "plugins": [
{
"name": "typescript-plugin-css-modules",
"options": {
"postcssOptions": {
"useConfig": true // I do use PostCSS (preset-env, and tailwind)
},
"rendererOptions": {
"sass": {
"includePaths": ["src/styles"] // contains `@mixins` definitions, which are imported with `@use`
}
}
}
}
] Sample of CSS module file: @use "$styles/tools/mixins";
.loader_page {
position: fixed;
inset: 0;
@include mixins.flex-center-column;
@apply gap-4;
@include mixins.full;
& > .loader {
& .circle_outer {
@apply text-blue-8;
@apply fill-current;
}
& .circle_inner {
@apply text-blue-3;
@apply fill-current;
}
}
& > .message {
font-size: 1.5em;
}
}
What I managed to verify so far
EDITWhile I was trying to provide more information, I thought about how not using a path alias Looks like I am using the path aliases configuration incorrectly, and I don't know how to debug it. @mrmckeb Could I ask for guidance on how I could debug it further? |
I am facing a similar issue as well (using @use). When I reference some .scss file by relative path, everythig works fine. But, when I reference same file absolutely, like this: or like that: I am facing issue described in this thread. Meaning, I have no intellisense with class names, and VSCode shows error (but I can compile code anyway). |
So I was able to get it fixed by using an absolute path in Can we have someone looking into it? Looks like some work to transform the relative path into an absolute based on the working directory would be required here
cc @mrmckeb |
@tleunen : could you share your solution? I am not able to make it work (by defining absolute path to "/src"). |
It's not really a solution though. I was simply able to make it work by using an absolute path in my tsconfig file.
|
@tleunen Thanks for quick response. I just wanted to try it as temporary solution. Anyway, I can add another piece of information - it doesn't seem to work on Windows, like:
(neither with / as path separator) |
Sorry for the slow reply, I was moving country (back in Australia now) and obviously that's eaten a lot of my time. Can someone provide a very simple reproduction for me? I can then use that to debug against and will provide a solution. |
there is a similar problem with
but, So there is no way to have VS work as expected in both files unless a relative path is used which is a pain for styling files. |
another interesting fact is that with NextJS, using relative addresses (or absolute without the leading slash) would result in warnings regarding caching issues so even this workaround probably won't work as well as I expected. I could not find a way to solve this problem with |
Seeing the similar thing in scss file. If |
Look here for examples to reproduce. I wasn't able to get it working properly in a CodeSandbox so you have to try in your own environment. |
@mrmckeb Was the info I provided enough for you to be able to test this? @import "sass/mixins/xyz";
.row {
@include rowContainer;
// ...
} The directory in my TSconfig, it requires me to put an absolute path, which is not great because the path is different for all devs. Simply using
The ts plugin must ran from the same directory as the sass file, which is why using |
Also hitting this issue, a bit more complexity to add to the potential solution is supporting TS types: i.e. in the
and in our tsconfig.json:
|
目前在xxx.module.scss中,使用@include是不支持的,会导致获得空对象 以下写法可以: |
@mrmckeb hello. |
I have pushed an MR to solve this problem with absolute paths. you can check it out before it gets merged (if it ever gets merged) by replacing the current version of the library to: npm install --save-dev github:falahati/typescript-plugin-css-modules#main --ignore-scripts --no-optional What it does is that it adds the current |
Hmm.. Thanks @falahati for the fix or tentative fix, but it doesn't seem to fix it for me. The right output when the scss doesn't contain any |
Since it's based automatically on the directory where the But even if I remove or change the abs paths, I can't find any way to make it work. I think the only good fix for this issue is to fix the |
@tleunen, so your project contains multiple |
I believe so, but I'm not entirely sure tbh.
|
but adding support for relative addresses still results in the same problem. the relative address has to be resolved against an absolute one and if the absolute address still changes per each The problem is that we are trying to replicate the way WebPack resolves files with TS which isn't really ideal. |
Ideally, it's resolved based on the absolute path where the config is in, not another tsconfig. Because repeating the following in everyone of them is not ideal. Works, but not ideal.
|
I am not very familiar with the typescript plugin API, but we currently use the From your description, this returns the directory of each child's |
Hello, when I using @include in CSS will cause classes to be an empty object, as shown in the following figure
Just remove @include
Maybe it's because mine @mixin is global
// vite.config.ts
The text was updated successfully, but these errors were encountered: