Cannot find variable (LESS)

I am importing some less files from node_modules into my project and it appears that WebStorm does not know how to deal with it. If I use any imported variable It gets a highlighed background and and the tool tip reads "cannot find variable xxx". It seems to be related to files imported from node_modules because if I move the files to my main project directory it seems to behave correctly.

Steps:

  1. Install bootstrap from npm
  2. create src directory in project and create main.less as child
  3. in main.less import bootstrap from node_modules like: @import "../node_modules/bootstrap/less/variables.less";
  4. In some-other-file.less also imported by main.less try referencing a variable like: color: @brand-primary;

I am rather new to WebStorm but see it has a lot of configuration options. Wondering if there is an easy configuration fix, or what solutions do other have?

Mac OS
WebStorm 2016.2.4

0
2 comments

As far as I can see, variable from bootstrap/less/variables.less is correctly resolved, but reported as being resolved by name only:

WebStorm uses the following approach for elements resolving in Less:

  1. If element can be resolved to declaration from current file or from explicitly imported files, then it is just resolved

  2. If element was not resolved after the first step (declaration is not found in current file/files explicitly imported into current file) then WebStorm tries to resolve it just by name no matter which file it's declared in ('global' elements). Resolved element is marked by weak-warning inspection 'Resolved by name only', as the IDE can't know if this element is 'global' or just not imported by mistake. You can disable this inspection if you don't like to see these warnings.

  3. If element still not resolved it is marked with warning 'Unresolved something'.

 

 

So, what error/warning do you see?

0
Avatar
Permanently deleted user

Thanks for the reply. I appreciate the explanation on variable resolution.

I updated to 2017 version and the problem appears to have gone away. :shrugs:

0

Please sign in to leave a comment.