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

Created on 19 Sep 2018  ยท  9Comments  ยท  Source: microsoft/vscode


  • 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
bug help wanted typescript

Most helpful comment

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.

All 9 comments

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

Still present in VS Code 1.35.1

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.

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.

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

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.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrkiley picture mrkiley  ยท  3Comments

DovydasNavickas picture DovydasNavickas  ยท  3Comments

borekb picture borekb  ยท  3Comments

philipgiuliani picture philipgiuliani  ยท  3Comments

lukehoban picture lukehoban  ยท  3Comments