-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Auto import does not pick up shortest path despite correct setting (JavaScript project with jsconfig.json) #54324
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
Looks like a duplicate of #53369, which means it was fixed in #53957. Please make sure to try out the nightly TypeScript version before you go through all the trouble of making a repro! Let me know if the nightly doesn’t solve your problem, but I’m going to go ahead and close because it looks identical. |
I just installed typescript@next extension and still seeing the same thing with 5.2.0-dev.20230517, and I think I am using the correct version by checking the command and the TS Server log Would you mind validating this? |
I can’t repro anything like |
Correct, the behavior has changed but is still not what a user would expect. (I was not clear in the previous comment) |
My bad, I was skimming for the most horrifying parts of the actual behavior 😄 |
Bug Report
🔎 Search Terms
I found a few closely related issues, and a few of them are marked as fixed. But since I am using a very recent version of the TS server, I was not expecting the issue to appear in my setup.
🕗 Version & Regression Information
TS Server 5.0.4 in VSCode 1.78.2
⏯ Playground Link
N/A -- project setup
💻 Code
Please use the code in this repository:
https://github.com/rwalle/ts-path-issue
🙁 Actual behavior
We have a monorepo setup without
node_modules
, and for simplicity, assume all packages live under the same folder. A team only develops one or a few packages, and they may have dependencies between them. In the example repository,package1
depends onpackage2
.jsconfig.json
has been correctly setup.After opening
setup1/package1
as the only workspace folder in VSCode, openfile1.js
and typebar
, the import path is../package2/file1
. The value for VSCode extension settingjavascript.preferences.importModuleSpecifier
is the default "shortest". If this is changed to "non-relative" or "project-relative", it gets worse -- it becomespackage1/../package2/file1
.Alternatively, under "shortest" setting, move
file1.js
to a subfolder and try to importbar
, you always seepackage1/../package2/file1
.However, if I manually type
import { bar } from 'p'
, it can findpackage2
. Also go to definition works properly if you uncomment the import at the beginning of that file.After opening
setup2
as the workspace folder in VSCode, typebar
, import path ispackage2/file1
. However we don't want to do that -- root folder is huge and nobody wants to have all folders and files from irrelevant packages visible in the workspace tree and potentially watched.🙂 Expected behavior
For
setup1/package1
, TS Service correctly provides the shortest pathpackage2/file1
.The text was updated successfully, but these errors were encountered: