-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Moving a folder that's imported using a path alias does not update the import paths. #59603
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
@Bunkerbewohner Thanks for posting this. Very clear. The problem is affecting a lot of people. Another user posted a similar repro repo here (which includes both aliased and relative imports for side-by-side comparison): I traced this VS Code regression with The TypeScript team engaged and suggested we post new issues, so here we are! |
Here's what I did, since the repro steps given don't align with the folder names in the repo:
2024-08-12.13-03-02.mp4Can you post a video along with the TS Server log operating on the provided repo? |
In #59119 it was pointed out that this was likely fixed by #59418. Have you tried using the latest TS build? It's very easy to set up with this extension |
Thanks a lot for looking into this! Here is a video using the latest TS build with the extension you suggested, where it didn't work. However, I then tried to reproduce it a second time (reset the repo, restarting VScode). tsnext.works.then.not.mp4So there seems to be some randomness, or at least some stateful condition involved. P.S. forgot to show it, but that's with the experimental VScode watcher enabled. When it's disabled, it always seems to work. Also just for posterity: the concrete repro steps are mentioned in the README of the repo (https://github.com/Bunkerbewohner/vscode-path-alias-problem?tab=readme-ov-file#bug-moving-a-folder-thats-imported-from-using-path-aliased-should-update-imports). |
Reminder to anybody else contributing to this thread: Please make sure to check and note your |
Quick note on something illustrated in this video that might be helpful in troubleshooting: when the import updating doesn't work, it doesn't even try. I.e. the "Update imports for ...?" popup (seen at 0:15) that appears after the "Are you sure you want to move...?" popup just never even pops up (would have been at 0:25). |
I've been testing this today and have some useful info to report. I believe I've gotten to the root of the unpredictability and apparent randomness. Environment
Experiment 1 (Simple)
Learned: There is state that is cleared by closing/opening project, allowing a single update imports to work. Restarting TS Server does not affect this. Question: To what extent does file location affect the state, and is moving it back to its original location relevant? Experiment 2 (Multiple Locations)
Learned: The state seems to be associated with how many times the file is moved and not the location. I.e. moving it back to its original location is no different than moving it elsewhere. The first move works, and subsequent ones don't. Question: Is the file itself relevant to the state, or is this a global state? Experiment 3 (Multiple Files)
Learned: The state appears to be associated with each file that is moved, only allowing the imports to be updated for the file the first time it is moved. But even in "broken" state, other files can still be moved (once). TakeawaysSo these experiments (hopefully easily reproducible) show a few things:
|
@Bunkerbewohner pls test with tonightβs nightly that would have fix #59625 to see if things resolved for you . If not give pls provide clear repro steps along with video and tsserver log . Thanks |
Thanks for your observations, @dkamins! That would be in line with the issue that @sheetalkamat linked, and it could essentially be a caching issue. @sheetalkamat I think you actually might have fixed it! I tested again today with tsnext20240814.mp4 |
I tested again in our actual app, not in my reproduction repo, and there even disabling the experimental Our app uses an older TypeScript 5.3.3. |
I am going to close this issue as fixed. If anyone has other repros, please file a new issue with clear repro steps, tsserver log and video as these things are tricky to track down without proper information. |
π Search Terms
"vscode path alias import"
π Version & Regression Information
β― Playground Link
No response
π» Code
Given some TS project where a folder is mapped using path aliases, e.g. mapping "@app" to the root folder.
Move the folder
folder
to a different parent, e.g.baz
, using VSCode.π Actual behavior
The imports referencing the moved files are not updated when the VScode setting
typescript.tsserver.experimental.useVsCodeWatcher
is enabled.When disabling the setting, the behavior is as expected (see below).
π Expected behavior
The import referencing the module should be updated automatically to
Additional information about the issue
See https://github.com/Bunkerbewohner/vscode-path-alias-problem for a reproduction repo.
The text was updated successfully, but these errors were encountered: