Description
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
- 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
- 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"] ) }
- .env
- Observe
styles
in App.tsx is typed as{}
, causing an angry zigzag in VS Code understyles["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