Skip to content
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

Cannot resolve *.module.css using paths of tsconfig.json #133

Open
mizdra opened this issue Mar 1, 2025 · 0 comments
Open

Cannot resolve *.module.css using paths of tsconfig.json #133

mizdra opened this issue Mar 1, 2025 · 0 comments
Labels
Status: Blocked Progress on the issue is Blocked Type: Fix Fix bug.

Comments

@mizdra
Copy link
Owner

mizdra commented Mar 1, 2025

css-modules-kit uses paths to resolve import specifiers.

Image

However, there are several edge cases that fail to resolve.

Case 1

One of these is Go to Definition in ts-plugin. Go to Definition fails if user clicks on import specifier with paths.

2025-03-01.18.32.25.mov

Case 2

Another is when the type definition file generated by codegen is type-checked by tsc.

// src/a.module.css
@import '@/d.module.css';
// src/d.module.css
.d_1 { color: red; }
// generated/a.module.css.d.ts
// @ts-nocheck
declare const styles = {
  ...(await import('@/src/d.module.css')).default,
  //                ^^^^^^^^^^^^^^^^^^
  //                This import speficier cannot be resolved by tsc.
  //                Therefore, the `(await import(...)) .default)` will be `any` type.
  //                Worse, `styles` will also be of `any` type.
};
export default styles;

Since styles will be any type, a type error will not be reported if you reference a non-existent class name from *.ts.

// src/a.ts
import styles from './a.module.css';
styles.unknown; // This should be reported as a type error
$ npx tsc
$ echo $?
0

Additional Information

The problem appears to be due to the following TypeScript behavior.

@mizdra mizdra added the Type: Fix Fix bug. label Mar 1, 2025
@mizdra mizdra changed the title Cannot resolve *.module.css using paths of tsconfig.json Cannot resolve *.module.css using paths of tsconfig.json or imports of package.json Mar 1, 2025
@mizdra mizdra changed the title Cannot resolve *.module.css using paths of tsconfig.json or imports of package.json Cannot resolve *.module.css using paths of tsconfig.json Mar 1, 2025
@mizdra mizdra added the Status: Blocked Progress on the issue is Blocked label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Blocked Progress on the issue is Blocked Type: Fix Fix bug.
Projects
None yet
Development

No branches or pull requests

1 participant