-
Notifications
You must be signed in to change notification settings - Fork 74
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
Type derivation fails when using less variables. #122
Comments
Hi @wingsico, thanks for raising this issue. Are you able to supply a small reproduction of this issue for me? |
Ok, here is the reproduction link: https://github.com/wingsico/typescript-plugin-css-modules-issue Focus on the |
I believe I'm experiencing a very similar issue. My project is based on CRA v4, using scss files, and CRACO to fix this bug with sass exports. The project compiles just fine like the OP's example, and I get the same empty object for the imported stylesheet. Style Object BrokenStyle Object WorkingIf you'd like me to put together a reproduction environment, just let me know and I'll do my best. |
The bug about importing is similar to this #114 . You can try for it. |
@wingsico Thank you for pointing me in the right direction! I was able to resolve my issue by reading through issue #114, #113, and #24. I hadn't realized my import path was non-standard. I was able to fix the issue just by changing the path but also through this plugin's options:
Thanks again for your quick support! |
Thanks for this @wingsico, I think I've found the issue. This fails: .App {
color: @blue;
} This works: @blue: rgb(0, 0, 255);
.App {
color: @blue;
} This is because the less rendered doesn't automatically pick up global variables, it processes each file independently. There are a few solutions:
An example of the second option (again, I don't recommend this) "plugins": [
{
"name": "typescript-plugin-css-modules",
"options": {
"rendererOptions": {
"less": {
"globalVars": {
"blue": "rgb(0, 0, 255)"
}
}
}
}
}
] What do you think would be a nice solution here for you? I think option 3 is possible, we could possibly automatically append |
Thanks for your reply @mrmckeb . Actually, the option 2 works for me (because my variables are defined in a common file). But I think the plugin can ignore this kind of problem, so that the type can be displayed normally. |
OK, thanks for the update @wingsico. I looked, and unfortunately I don't see an option in Less to build with errors. So if a variable can't be found, classname generation will fail. If you're happy with that solution for now, can we close this issue? Or did I misunderstand? |
@mrmckeb OK, I will close it soon. Thanks for your help. :) |
@mrmckeb {
loader: "style-resources-loader",
options: {
patterns: path.resolve(__dirname, "../src/common/global-style/*.less"),
},
}, its desciption:
In this development environment, i will use global variables in many less files(without |
Hey, is there any progress with this problem? I think many less user suffer from this. |
Describe the bug
Type derivation fails when using less variables.
To Reproduce
Steps to reproduce the behavior:
Install dependencies & prepare the tsconfig & declare type & use workspace's ts version.
create index.ts & create index.module.less & fill style without less variables.
Now it works well
Add less variables to the less file.
See error
Expected behavior
When I use less variables, it should be work well too.
Screenshots
See ** To Reproduce **
Desktop (please complete the following information):
Additional context
These less variables are injected through less-loader.
The text was updated successfully, but these errors were encountered: