-
Notifications
You must be signed in to change notification settings - Fork 12.8k
auto-import using yarn link protocol, is importing the path, rather than the name #48712
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
Comments
I'll also add, fwiw, if you already have an existing import using the module name, it will add to that existing import, rather than create a new one using the path. e.g. in the example above, if I also add
rather than:
|
Please share a minimal example project that demonstrates this problem |
Okay, after further investigation while creating a minimal example project, I realized that vscode actually is completely unaware of the yarn link protocols when it comes to auto-importing. What is actually happening here, is setting up a So I suppose, rather than a bug, this should be a feature-request for vscode to recognize the existence of a yarn link protocol, and use that for imports. Here's the repro (note the yarn-link-protocol-defect branch). If you auto-import If you've run |
I would also love to see this feature, which is sorely missed for people using Yarn 2+ and absolute imports via the link protocol. |
Moving upstream to get more feedback from the TS team Possible related: #37414 |
Does any package manager besides yarn respect this protocol? |
Not that I'm aware of. I believe this is a yarn-specific protocol. |
This should also work cross-file in the same project as long as you have a tsconfig.json/jsconfig.json. I.e., once anything in your project imports from the symlink path, do auto-imports in other files use the symlink path too? |
Oh, interesting! So this definitely was not happening for me. Every time I'd auto-import, it would use the incorrect version, based on the root path, regardless if that import exists in other files, or other similar imports exist in the current file. But your comment about tsconfig/jsconfig gave me an idea. I removed the |
Hesitant to commit to adding yarn-specific resolution logic when the time-tested workaround of “just write it once and you’re good to go” is working, but will listen for feedback and gauge demand here in this thread. |
FWIW, this will be much less painful for me now, knowing the behavior without a |
Uh oh!
There was an error while loading. Please reload this page.
In my package.json, I have the following yarn link protocols set up in
dependencies
:When I auto-import a dependency from either of these files, the import statement looks like this:
And while this does compile and work fine, I would expect the imports to look like this:
If I manually adjust the imports to my preferred format, it also works fine. But why would vscode be pulling the import path from the right side of the declaration, rather than the left side? Am I incorrect in my assumption that it should be using the 'name', rather than the path for the imports? All other dependencies reference the package name when being imported.
Verified that this behaves the same with all extensions disabled.
VS Code version: Code 1.62.3 (Universal) (ccbaa2d27e38e5afa3e5c21c1c7bef4657064247, 2021-11-17T07:59:13.865Z)
OS version: Darwin arm64 21.1.0
Restricted Mode: No
System Info
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Extensions (26)
(1 theme extensions excluded)
A/B Experiments
The text was updated successfully, but these errors were encountered: