typescript-plugin-css-modules icon indicating copy to clipboard operation
typescript-plugin-css-modules copied to clipboard

Empty object required for path aliasing to work

Open mrmckeb opened this issue 1 year ago • 1 comments

I've found a fix for the problem, and a potential improvement in either the code or the docs (or both!).

This line sets up the alias imports: https://github.com/mrmckeb/typescript-plugin-css-modules/blob/4879b0418610eff871472ffa2cc592728d84d2be/src/helpers/getCssExports.ts#L117

It needs the presence of baseUrl and paths in your tsconfig to create an alias importer. baseUrl gets a default value, so this check does nothing, but paths need to exist (even if an empty object), to create the path matcher.

The easy fix is just to add the following to your tsconfig:

 "compilerOptions": {
   "paths": {}
 }

This then allows the alias importer to resolve relative to your tsconfig, as well as relative to the file it is resolving.

Originally posted by @RMHonor in https://github.com/mrmckeb/typescript-plugin-css-modules/issues/267#issuecomment-2380861262

mrmckeb avatar Oct 10 '24 07:10 mrmckeb

Jesus, how did I finally find this after wasting hours! Thank you. Sorely needs to be merged, or at least documented.

drewlustro avatar Feb 12 '25 23:02 drewlustro