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

moving TypeScript files in explorer fails to update/prompt imports when containing folder is moved #58987

Open
dontsave opened this issue Sep 19, 2018 · 14 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities typescript Typescript support issues
Milestone

Comments

@dontsave
Copy link

  • VSCode Version: 1.27.2
  • OS Version: Win 10
  • Typescript: 3.0.3

Steps to Reproduce:

  1. Set update imports on move typescript setting to prompt
  2. Create an empty project with 2 typescript files, one importing from the other.
  3. In the explorer manually move the depended upon file to a new directory. You will be prompted to update the import. This works fine.
  4. Now move that directory into ANOTHER new directory.
  5. This time there is no prompt and the import will be broken
@amitnovick
Copy link

amitnovick commented Mar 21, 2019

Found that this issue has bigger impact:

  • Also relevant to JavaScript files with javascript.updateImportsOnFileMove.enabled option
  • javascript.updateImportsOnFileMove.enabled can be of: {'prompt', 'always'} and fail to update imports in both cases.
  • Applies to both Directory Move in Explorer and Directory Rename the same.

Minimal reproduce:

  1. Set "javascript.updateImportsOnFileMove": "always" in VSCode settings
  2. Set up two files: app.js and lib/components/a.js in the following filesystem hierarchy:
├── app.js
└── lib
    └── components
        └── a.js
  1. Insert the following snippets into the files:
// lib/components/a.js
module.exports = 1;
// app.js
const a = require('./lib/components/a.js');
  1. Move lib/components directory to components (one hierarchy level up) using the Explorer (drag and drop with mouse):
├── app.js
├── components
│   └── a.js
└── lib

Issue

Expected (app.js import should be updated):

// app.js
const a = require('./components/a.js');

In reality (app.js import was not updated):

// app.js
const a = require('./lib/components/a.js');

Tested on VSCode stable 1.32.3

UPDATE: Bug still present at VSCode stable 1.33.1

@jcalmonte
Copy link

Still present in VS Code 1.35.1

@SAkhil95
Copy link

Hi All,
@mjbvz
This issue seems fixed now in the latest update 1.40.1

However.. it is not prompting even if I selected prompt.

settings.json shows "javascript.updateImportsOnFileMove.enabled": "prompt" but its behaving as if user selected always.

Having said that, I still believe the current behavior is the correct one as there may be times where user rejects the auto update prompt accidentally which may break the code.

@jonrimmer
Copy link

It's not properly fixed. Sometimes moving a folder updates the imports of the TS files inside it. Sometimes it doesn't. There doesn't seem to be any reason for why/when, it's just random. E.g. I can try to move a folder and none of the imports are updated. I reset my git state, try again, and it works. Sometimes even when it does work, broken copies of the original files get left behind in the source directory.

@AveryTheDev
Copy link

AveryTheDev commented May 28, 2020

I am also experiencing this issue still. TypeScript or JS files regardless of whether it is in a folder or not. Auto import enabled in settings

@mjbvz mjbvz added the help wanted Issues identified as good community contribution opportunities label Jul 7, 2020
@am4zed
Copy link

am4zed commented Aug 13, 2020

I am also experiencing what @jonrimmer describes. I moved a folder containing subfolders and files to a new folder and was shown the prompt asking if I'd like to update imports and clicked yes. The folder and its contents were moved the new location but versions of some of the files - identical apart from containing non-updated import paths - were left behind in the original location.

@Danil00524
Copy link

I've the same problem. Has somebody done it?

@DustInComp
Copy link

DustInComp commented Nov 12, 2020

Might be caused by the consecutive prompts, one for confirming the Move, one for the import updating.
The second prompt seems to open reliably when you tick "Don't show again" on the first one.

@bartosz-apptimia
Copy link

I've got this problem as well. Moving files works well, but moving folders doesn't update the paths.

@alexc777
Copy link

I have the same problem, I am working on an ionic project

@SayefReyadh
Copy link

For a typescript project faced similar issue from in my end for the following settings,

"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always",

I have changed the settings to promt which seems to solve this issue for now.

"javascript.updateImportsOnFileMove.enabled": "prompt",
"typescript.updateImportsOnFileMove.enabled": "prompt",

My VS Code Version

Version: 1.59.0 (system setup)
Commit: 379476f0e13988d90fab105c5c19e7abc8b1dea8
Date: 2021-08-04T23:13:12.822Z

@mjbvz mjbvz added this to the Backlog milestone Dec 5, 2022
@mitsuru793

This comment was marked as duplicate.

@nicitaacom
Copy link

nicitaacom commented Jan 26, 2024

I have this same issue with this settings:

"typescript.updateImportsOnFileMove.enabled": "always",

For me this settings don't help

"javascript.updateImportsOnFileMove.enabled": "prompt",
"typescript.updateImportsOnFileMove.enabled": "prompt",
665f959d-f30d-46ac-b813-b882dfe5ae88.mp4

I'm expect that import path will be updated once file/files moved to antoher directory

@kistgab

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests