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

Debug Failure prevents renaming imports on file move #40386

Closed
s4m0r4m4 opened this issue Sep 4, 2020 · 7 comments · Fixed by #44484
Closed

Debug Failure prevents renaming imports on file move #40386

s4m0r4m4 opened this issue Sep 4, 2020 · 7 comments · Fixed by #44484
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@s4m0r4m4
Copy link

s4m0r4m4 commented Sep 4, 2020

TypeScript Version: 3.9.7

Search Terms:
update imports on rename, update imports on file move

Expected behavior:
When renaming a typescript file/folder in VS code, import statements pointing at the file in question should be updated.

Actual behavior:
Although this used to work, I am now running into an issue where the imports are no longer being updated.

I ran tsserver with verbose logs, and noticed the following issue which seems related to the behavior I'm seeing (entire log file uploaded too, you can see this around line 5246 of tsserver.log):

Info 2254 [12:43:47.630] event:
    {"seq":0,"type":"event","event":"projectLoadingFinish","body":{"projectName":"c:/AIMDev/CI-Web/libs/lib-forms/tsconfig.spec.json"}}
Info 2255 [12:43:47.630] event:
    {"seq":0,"type":"event","event":"telemetry","body":{"telemetryEventName":"projectInfo","payload":{"projectId":"e17614f21b281be9dace752d26bd0c1eef44fe366fc005e02deb7ef7b1277935","fileStats":{"js":0,"jsSize":0,"jsx":0,"jsxSize":0,"ts":3,"tsSize":3450,"tsx":0,"tsxSize":0,"dts":87,"dtsSize":1935892,"deferred":0,"deferredSize":0},"compilerOptions":{"baseUrl":"","declaration":false,"emitDecoratorMetadata":true,"experimentalDecorators":true,"importHelpers":true,"lib":["es2017","dom"],"module":"commonjs","moduleResolution":"node","paths":"","preserveSymlinks":true,"resolveJsonModule":true,"rootDir":"","skipLibCheck":true,"sourceMap":true,"strict":true,"target":"es6","typeRoots":[""],"outDir":"","types":["",""]},"typeAcquisition":{"enable":false,"include":false,"exclude":false},"extends":true,"files":true,"include":true,"exclude":true,"compileOnSave":false,"configFileName":"other","projectType":"configured","languageServiceEnabled":true,"version":"3.9.7"}}}
Err 2256  [12:43:48.478] Exception on executing command {"seq":255,"type":"request","command":"getEditsForFileRename","arguments":{"oldFilePath":"c:/AIMDev/CI-Web/libs/lib-forms/src/lib/i18n/lib-forms-messages.service.ts","newFilePath":"c:/AIMDev/CI-Web/libs/lib-forms/src/lib/i18n/aim-forms-messages.service.ts"}}:

    Debug Failure.

    Error: Debug Failure.
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:117897:61
        at forEachProperty (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:118061:17)
        at updateTsconfigFiles (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:117887:9)
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:117851:13
        at Function.ChangeTracker.with (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:126223:17)
        at Object.getEditsForFileRename (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:117850:49)
        at Proxy.getEditsForFileRename (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:139227:23)
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149297:146
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:147536:36
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144905:25
        at Map.forEach (<anonymous>)
        at ProjectService.forEachProject (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144898:41)
        at ProjectService.forEachEnabledProject (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144903:22)
        at combineProjectOutputFromEveryProject (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:147535:28)
        at IOSession.Session.getEditsForFileRename (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149297:31)
        at Session.handlers.ts.createMapFromTemplate._a.<computed> (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:148075:61)
        at c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149555:88
        at IOSession.Session.executeWithRequestId (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149546:28)
        at IOSession.Session.executeCommand (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149555:33)
        at IOSession.Session.onMessage (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:149579:35)
        at Interface.<anonymous> (c:\Users\A9FZGZZ\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:150895:27)
        at Interface.emit (events.js:203:13)
        at Interface._onLine (readline.js:316:10)
        at Interface._normalWrite (readline.js:461:12)
        at Socket.ondata (readline.js:172:10)
        at Socket.emit (events.js:203:13)
        at addChunk (_stream_readable.js:295:12)
        at readableAddChunk (_stream_readable.js:276:11)
        at Socket.Readable.push (_stream_readable.js:210:10)
        at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)

I have also attached the other tsserver.log file (named tsserver2.log in this issue). It didn't contain any explicit errors, but did contain the following:

Info 302  [12:46:46.283] Project '/dev/null/inferredProject1*' (Inferred)
Info 302  [12:46:46.283] 	Files (0) NoProgram

Perhaps it's related, perhaps not.

Playground Link: n/a

Related Issues:
#28771 (Mac specific)
#30535 (performance-related)
#26927 (Seems this issue was fixed back in 2018, I'm definitely on a newer version of TS)
#24857

Attachments:
tsserver.log
tsserver2.log

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 9, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.1.1 milestone Sep 9, 2020
@OliverJAsh
Copy link
Contributor

Potentially related: #37685

I am running into this issue, or one similar to it, when trying to rename a folder. (Renaming files seems to work.)

I discovered that if I disable importHelpers, renames start working again: #37685 (comment)

Info 1725 [12:17:56.433] request:
    {"seq":31,"type":"request","command":"getEditsForFileRename","arguments":{"oldFilePath":"/Users/oliverash/Development/unsplash-web/app/components/Test","newFilePath":"/Users/oliverash/Development/unsplash-web/app/components/Test2"}}
Err 1726  [12:17:56.563] Exception on executing command {"seq":31,"type":"request","command":"getEditsForFileRename","arguments":{"oldFilePath":"/Users/oliverash/Development/unsplash-web/app/components/Test","newFilePath":"/Users/oliverash/Development/unsplash-web/app/components/Test2"}}:

    Debug Failure. False expression.

    Error: Debug Failure. False expression.
        at Object.createRange (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:17182:18)
        at createStringRange (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:121138:19)
        at updateImportsWorker (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:121134:64)
        at _loop_4 (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:121044:13)
        at updateImports (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:121068:13)
        at /Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:120937:13
        at Function.ChangeTracker.with (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:129480:17)
        at Object.getEditsForFileRename (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:120935:49)
        at Proxy.getEditsForFileRename (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:143872:23)
        at /Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:154709:173
        at /Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:152823:36
        at /Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:150069:25
        at Map.forEach (<anonymous>)
        at ProjectService.forEachProject (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:150062:41)
        at ProjectService.forEachEnabledProject (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:150067:22)
        at combineProjectOutputFromEveryProject (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:152822:28)
        at IOSession.Session.getEditsForFileRename (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:154709:58)
        at Session.handlers.ts.Map.ts.getEntries._a.<computed> (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:153427:61)
        at /Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:155017:88
        at IOSession.Session.executeWithRequestId (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:155008:28)
        at IOSession.Session.executeCommand (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:155017:33)
        at IOSession.Session.onMessage (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:155041:35)
        at Interface.<anonymous> (/Users/oliverash/Development/unsplash-web/node_modules/typescript/lib/tsserver.js:157257:27)
        at Interface.emit (events.js:223:5)
        at Interface._onLine (readline.js:315:10)
        at Interface._normalWrite (readline.js:460:12)
        at Socket.ondata (readline.js:172:10)
        at Socket.emit (events.js:223:5)
        at addChunk (_stream_readable.js:309:12)
        at readableAddChunk (_stream_readable.js:290:11)
        at Socket.Readable.push (_stream_readable.js:224:10)
        at Pipe.onStreamRead (internal/stream_base_commons.js:181:23)

@justinmayhew
Copy link

justinmayhew commented Nov 29, 2020

I'm getting the same error using VS Code when renaming a file in a fairly small monorepo using project references. Feel free to use that project to reproduce the issue. I suspect it may have something to do with project references because I'm able to rename/refactor without issue in a project with a single tsconfig.json.

Here's the TypeScript server log when attempting to rename lib/string/src/concat.ts to lib/string/src/concatenate.ts: rename-error.txt

The file rename is successful, but references are not updated as expected.

I also tested this in WebStorm which was able to perform the above refactor successfully.

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 11, 2020
@s4m0r4m4
Copy link
Author

I can confirm that renaming imports still is not working in v1.52.1

@peterboyer
Copy link

I'm getting the same error using VS Code when renaming a file in a fairly small monorepo using project references.

I also started experiencing this problem (renaming imports not working) when building a monorepo project using references.

@bradleyayers
Copy link

bradleyayers commented May 10, 2021

I'm getting the same error using VS Code when renaming a file in a fairly small monorepo using project references.

I also started experiencing this problem (renaming imports not working) when building a monorepo project using references.

I debugged this a while ago and in my case it was because i was using include: [] rather than files: [] in my "solution" tsconfig.json files. There's a code path in TS that expected include to be non-empty if it's defined. It's in the code that tries to figure out which project the file being renamed belongs to (or maybe it's the bit figuring out which projects the newly renamed file will match) so it can update them accordingly. So it may not be limited to the tsconfig.json that target the file being renamed, it could be any in the repo.

@peterboyer
Copy link

I debugged this a while ago and in my case it was because i was using include: [] rather than files: [] in my "solution" tsconfig.json files.

YES!!! This is it! Thank you @bradleyayers This change made it all work for me!

And by "solution" tsconfig.json, I changed the my monorepo's root tsconfig.json file to use "files": [] instead of "include": [] and suddenly VSCode offered me to automatically update file imports on rename and move!

For anyone else wondering my monorepo/typescript structure is:

// tsconfig.json (monorepo root)

{
  "compilerOptions": {
    "composite": true // and no other compilerOptions, refer to tsconfig.base.json
  },
-  "include": [],
+  "files": [], // changed from "include"
  "references": [
    { "path": "./packages/a" },
    { "path": "./packages/b" },
    { "path": "./packages/c" },
    ... // etc your packages
  ]
}

And then for other "leaf" project tsconfig files:

// packages/a/tsconfig.json

{
  "extends": "../../tsconfig.base", // definition below
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./lib"
  },
  "include": ["src/**/*"],
  "exclude": ["**/__tests__", "**/__mocks__"],
  "references": [
    { "path": "../b" },
    { "path": "../c" },
    ... // anything other repo packages this package references
  ]
}

And my tsconfig.base.json (project root) as extended from is:

// tsconfig.base.json

{
  "compilerOptions": {
    "composite": true,

    "lib": ["dom", "dom.iterable", "esnext"],
    "target": "esnext",
    "module": "commonjs",

    // ... and all my other project config preferences etc
}

There's a code path in TS that expected include to be non-empty if it's defined. It's in the code that tries to figure out which project the file being renamed belongs to (or maybe it's the bit figuring out which projects the newly renamed file will match) so it can update them accordingly.

This has to be it. Something unintended is happening when using "include" (as ideally intended) instead of "files" (workaround). First time I've seen it required when considering all the typescript references and other monorepo tutorials etc don't catch this issue.

@bradleyayers
Copy link

Something else you might enjoy is that Error: Debug Failure. False expression. means an assertion failed ("False exprssion"), and if you attach a debugger it conveniently has a debugger statement in the assertion helper so you break on the exact spot you need. It makes debugging issues like this fairly approachable, you just need to go up a few levels in the call stack and poke around a bit.

elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Jun 7, 2021
Avoid the assumption that there are always include patterns: when there
are none (and therefore the renamed file didn't match anyway), just skip
the test for added include.

Also change the code to use `return` to make it flatter.

(Also get rid of a redundant type.)

Fixes microsoft#40386.
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jun 7, 2021
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Jun 21, 2021
Avoid the assumption that there are always include patterns: when there
are none (and therefore the renamed file didn't match anyway), just skip
the test for added include.

Also change the code to use `return` to make it flatter.

(Also get rid of a redundant type.)

Fixes microsoft#40386.
elibarzilay added a commit that referenced this issue Jun 21, 2021
Avoid the assumption that there are always include patterns: when there
are none (and therefore the renamed file didn't match anyway), just skip
the test for added include.

Also change the code to use `return` to make it flatter.

(Also get rid of a redundant type.)

Fixes #40386.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants