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

TS imports are not refactored on file rename/move when resolveJsonModule and esModuleInterop are true in tsconfig.json #26927

Closed
mjbvz opened this issue Sep 5, 2018 · 2 comments
Assignees

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Sep 5, 2018

From @mezei-adrian on August 2, 2018 14:35

  • VSCode Version: 1.25.1
  • OS Version: Windows 10.0.17134.0
  • TS Version: 3.0.1

Steps to Reproduce:

  1. Create an empty project with 4 files at the project root as it follows:
// A.ts
import { log } from "./B";
import message from "./message.json";
log(message.text);
// B.ts
export function log(message: string): any {
    console.log(message);
}
// message.json
{ "text": "helo" }
// tsconfig.json
{
    "compilerOptions": {
        "resolveJsonModule": true,
        "esModuleInterop": true
    }
}
  1. Now if you create a folder in the project root folder and move the referenced (B.ts) file to it, the reference to it in A.ts does not update.

The issue is the same when the imported JSON file is moved/renamed.

Copied from original issue: microsoft/vscode#55665

@mjbvz mjbvz self-assigned this Sep 5, 2018
@mjbvz mjbvz added Domain: JavaScript The issue relates to JavaScript specifically Needs More Info The issue still hasn't been fully clarified labels Sep 5, 2018
@mjbvz mjbvz removed Needs More Info The issue still hasn't been fully clarified Domain: JavaScript The issue relates to JavaScript specifically labels Sep 5, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented Sep 5, 2018

This seems to be fixed in typescript@next.

The original error was:

[Error  - 3:23:50 PM] 'getEditsForFileRename' request failed with error.
Error processing request. Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at updateImportsWorker (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:95952:67)
    at _loop_3 (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:95895:13)
    at updateImports (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:95919:13)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:95789:13
    at Function.ChangeTracker.with (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:102976:17)
    at Object.getEditsForFileRename (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:95787:49)
    at Object.getEditsForFileRename (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:111803:23)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119363:146
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117838:36
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:116304:25
    at Map.forEach (<anonymous>)
    at ProjectService.forEachProject (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:116298:41)
    at ProjectService.forEachEnabledProject (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:116302:22)
    at combineProjectOutputFromEveryProject (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:117837:28)
    at IOSession.Session.getEditsForFileRename (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119363:31)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:118281:61)
    at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119531:88
    at IOSession.Session.executeWithRequestId (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119522:28)
    at IOSession.Session.executeCommand (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119531:33)
    at IOSession.Session.onMessage (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:119551:35)
    at Interface.<anonymous> (/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js:120805:27)
    at emitOne (events.js:116:13)
    at Interface.emit (events.js:211:7)
    at Interface._onLine (readline.js:282:10)
    at Interface._normalWrite (readline.js:424:12)
    at Socket.ondata (readline.js:141:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

@mezei-adrian Please try upgrading your workspace to use typescript@next by following these instructions

@mjbvz mjbvz closed this as completed Sep 5, 2018
@adrian-mezei
Copy link

adrian-mezei commented Sep 9, 2018

I upgraded the workspace and the imports are still not refactored. I also observed, that this issue only holds if a JSON file is imported. So if I modify my example A.ts file to

// A.ts
import { log } from "./B";

then the imports are renamed properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants