typescript-plugin-css-modules
typescript-plugin-css-modules copied to clipboard
Empty object required for path aliasing to work
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
baseUrlandpathsin your tsconfig to create an alias importer.baseUrlgets a default value, so this check does nothing, butpathsneed 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
Jesus, how did I finally find this after wasting hours! Thank you. Sorely needs to be merged, or at least documented.