Skip to content

"importModuleSpecifier" ignores "paths" in tsconfig when auto importing #40116

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

Closed
Floriferous opened this issue Aug 17, 2020 · 6 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@Floriferous
Copy link

I have 2 conflicting settings, that I wish were making a different compromise:

  • javascript.preferences.importModuleSpecifier: "relative" in settings.json
  • compilerOptions.paths in tsconfig.json

I defined an alias in paths, and would like all imports to it to be absolute imports. For the rest of my code, I want to use relative paths. However, when setting both these settings above, autoImport always resolves the aliased path relatively, instead of absolutely.

Here's a reproduction: https://github.com/Floriferous/paths-resolution

When you go into test.js and try to import someVar, it will only suggest to import it with a relative path. I wonder if this is by design, or if this is something that could be altered?

  • VSCode Version: 1.48.0
  • OS Version: macOS 10.15.6

EDIT: This has been happening for a long time, I just decided to open an issue now.

@mjbvz
Copy link
Contributor

mjbvz commented Aug 17, 2020

Does this reproduce in the latest VS Code insiders build too?

@Floriferous
Copy link
Author

Yes it does.

@mjbvz mjbvz transferred this issue from microsoft/vscode Aug 18, 2020
@mjbvz mjbvz removed their assignment Aug 18, 2020
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 3, 2020
@RyanCavanaugh
Copy link
Member

Duplicate #36235

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@andrewbranch
Copy link
Member

@Floriferous there’s a lot going on in your repro. What’s the symlink for? Your tsconfig says to exclude the symlink, but include the realpath. Those both refer to the same folder, and the exclude wins, so constants.js is excluded from the program, which is why it doesn’t show up in your auto-import at all.

I defined an alias in paths, and would like all imports to it to be absolute imports. For the rest of my code, I want to use relative paths.

Suppose you had another file in shared. From that file, how would you expect to reference shared/constants? As "shared/constants" or "./constants"?

@andrewbranch
Copy link
Member

The title made it sound like this was a duplicate of #36235, but it’s really a duplicate of #36624.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants
@andrewbranch @RyanCavanaugh @Floriferous @mjbvz @typescript-bot and others