Skip to content

Does not use SASS_PATH environment variable when resolving imports #49

Closed
@PsiRadish

Description

@PsiRadish

Describe the bug
I have a sass file containing variable/function/mixin stuff located at /src/theme/_module-basics.scss.
In my .env file I have

SASS_PATH=./src/theme

which allows me to import _module-basics.scss into any CSS module regardless of its location with just

@import "module-basics";

However, after importing such a CSS module into a tsx file, it is typed only as {} in VS Code, and I see this in the TS Server log:

Info 56   [10:6:34.575] [typescript-plugin-css-modules] Failed Error: Can't find stylesheet to import.
  ╷
1 │ @import "module-basics";

Only if I change the @import to use a path relative to the module file, like say...

@import '../theme/module-basics';

...do I get a proper type definition for the CSS module.

To Reproduce

  1. Add the following file/folder structure to a CRA project configured to use typescript-plugin-css-modules:
    (root)
    ├ .env
    └ /src
      ├ App.tsx
      ├ App.modules.scss
      └ /theme
        └ _module-basics.scss
    
  2. File contents:
    • .env
      SASS_PATH=./src/theme
      
    • _module-basics.scss
      $nice-color: #FF0080;
    • App.modules.scss
      @import "module-basics";     
      .nicely-colored {
          color: $nice-color;
      }
    • App.tsx
      /* React, etc. imports */
      
      import styles from './App.module.scss'; // styles assigned Type of {}
      
      function App(props: {}) {
          return (
              <span className={styles["nicely-colored"]}>This is nice.</span> // angry zigzag under styles["nicely-colored"]
          )
      }
  3. Observe styles in App.tsx is typed as {}, causing an angry zigzag in VS Code under styles["nicely-colored"]

Expected behavior
This plugin and/or its dependencies are able to use the contents of SASS_PATH to resolve @import "module-basics" in App.module.scss.
Following which, styles in App.tsx is provided a Type based on the classes/ids in App.module.scss, so there is no angry under styles["nicely-colored"].

Desktop

  • OS: Windows 10

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions