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

Autocomplete not working with global path #227

Closed
abaksha-sc opened this issue May 23, 2023 · 4 comments · Fixed by #229
Closed

Autocomplete not working with global path #227

abaksha-sc opened this issue May 23, 2023 · 4 comments · Fixed by #229

Comments

@abaksha-sc
Copy link

abaksha-sc commented May 23, 2023

Describe the bug
Next.js often use global path alias @ for sources (defines in tsconfig.json through "baseUrl": "." and "paths": { "@/*": ["./src/*"] }).
And in this case autocomplete for CSS-module doesn't work.

To Reproduce
Steps to reproduce the behavior:

  1. Go to sandbox sources
  2. Make sure first line is defined with absolute path: import styles from "@/styles/home.module.scss";
  3. Over cursor to variable styles on line 8.
  4. See the variable definition as

image

Expected behavior
Please modify sources:

  1. comment first line with absolute path import styles from "@/styles/home.module.scss";
  2. uncomment second line with relative path import styles from "../styles/home.module.scss";
  3. Hover variable styles on line 8.

In this case you will see the valid definition with CSS-classes as object keys like:

image

TypeScript version: 5.0.4
Plugin version: 5.0.1

@hou5emd
Copy link

hou5emd commented Jun 1, 2023

@abaksha-sc check on 4.2.3, because it`s work for me

@SLTKA
Copy link

SLTKA commented Jun 2, 2023

I think issue is in this line

languageServiceHost.getResolvedModuleWithFailedLookupLocationsFromCache
getResolvedModuleWithFailedLookupLocationsFromCache is not defined by default in TS, like in my VSCode language server it stays undefined for TS 4.9.5 and 5.1.3 (haven't tested others).

Which config can I use to have getResolvedModuleWithFailedLookupLocationsFromCache defined?

Another challenge that we can override isCSS but not isRelative. Maybe having custom resolver override would be the easiest solution if this is possible, or fallback to Node resolution (just thinking at loud, haven't check this ideas)


Update:

For us the issue with paths is not the biggest challenge as we still can use relative paths. However, if we import a CSS module from a NPM package this plugin can't resolve it, manually adding (patching package)

} else if (isCSS(moduleName) && typeof require.resolve === "function") {
                  return {
                      extension: ts.Extension.Dts,
                      isExternalLibraryImport: true,
                      resolvedFileName: require.resolve(moduleName),
                  };
                }

on line https://github.com/mrmckeb/typescript-plugin-css-modules/blob/2e502074b9f370dd8d970bc7e6e8a970bf57ba59/src/index.ts#LL205C10-L205C10 solves our issue, would be nice to have something similar included

@marcoms
Copy link

marcoms commented Jun 9, 2023

Also facing this issue so having to just use relative paths which isn't ideal. It would be great to get hints working for absolute paths, especially as the '@/...' style is becoming more common.

@sshrshnv
Copy link

sshrshnv commented Oct 4, 2023

@mrmckeb when will this fix be published in npm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants