Repository: TypeScript
Issue: <semantic>  TS Server Error Debug Failure when moving to a js file
Labels: Bug,Domain: Refactorings,Fix Available

Repo/file: https://github.com/xtermjs/xterm.js/blob/995ccc72f85dc2f8ab1353dacbfea12202b4a16c/demo/start.js

![Recording 2024-07-10 at 06 35 22](https://github.com/user-attachments/assets/0b93af70-6f81-4396-8fe7-55ab367d6498)

TypeScript output:

```
2024-07-10 06:36:36.984 [trace] <semantic> Sending request: getMoveToRefactoringFileSuggestions (2566). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9
}
2024-07-10 06:36:36.985 [trace] <semantic> Response received: getMoveToRefactoringFileSuggestions (2566). Request took 1 ms. Success: true  {
    "newFileName": "d:/Tyriar/xterm.js/demo/newFile.js",
    "files": [
        "d:/Tyriar/xterm.js/out-esbuild/vs/base/browser/canIUse.js",
        "d:/Tyriar/xterm.js/out-esbuild/browser/Terminal.test.js",
        "d:/Tyriar/xterm.js/demo/server.js"
    ]
}
2024-07-10 06:36:38.868 [trace] <semantic> Sending request: getEditsForRefactor (2567). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9,
    "action": "Move to file",
    "refactor": "Move to file",
    "interactiveRefactorArguments": {
        "targetFile": "d:/Tyriar/xterm.js/out-esbuild/vs/base/browser/canIUse.js"
    }
}
2024-07-10 06:36:38.872 [trace] <semantic> Response received: getEditsForRefactor (2567). Request took 4 ms. Success: false . Message: Error processing request. Debug Failure.
Error: Debug Failure.
    at Object.addImportFromExportedSymbol (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:154158:32)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:144203:19
    at Map.forEach (<anonymous>)
    at addTargetFileImports (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:144197:17)
    at getNewStatementsAndRemoveFromOldFile (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143427:3)
    at doChange3 (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143411:3)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143396:79
    at _ChangeTracker.with (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:174213:5)
    at Object.getRefactorEditsToMoveToFile [as getEditsForAction] (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:143396:62)
    at Object.getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:142518:31)
    at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149854:32)
    at IpcIOSession.getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:190993:49)
    at getEditsForRefactor (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:189211:43)
    at c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191397:69
    at IpcIOSession.executeWithRequestId (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191389:14)
    at IpcIOSession.executeCommand (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191397:29)
    at IpcIOSession.onMessage (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191439:51)
    at process.<anonymous> (c:\Users\Daniel\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:523:14)
    at process.emit (node:events:519:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
2024-07-10 06:36:38.879 [trace] <semantic> Sending request: getApplicableRefactors (2568). Response expected: yes. Current queue length: 0 {
    "file": "d:\\Tyriar\\xterm.js\\demo\\start.js",
    "startLine": 2,
    "startOffset": 9,
    "endLine": 2,
    "endOffset": 9,
    "triggerReason": "implicit",
    "includeInteractiveActions": true
}
2024-07-10 06:36:38.880 [trace] <semantic> Response received: getApplicableRefactors (2568). Request took 1 ms. Success: true  [
    {
        "name": "Convert export",
        "description": "Convert default export to named export",
        "actions": [
            {
                "name": "Convert default export to named export",
                "description": "Convert default export to named export",
                "kind": "refactor.rewrite.export.named",
                "notApplicableReason": "Could not find export statement"
            },
            {
                "name": "Convert named export to default export",
                "description": "Convert named export to default export",
                "kind": "refactor.rewrite.export.default",
                "notApplicableReason": "Could not find export statement"
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert namespace import to named imports",
        "actions": [
            {
                "name": "Convert namespace import to named imports",
                "description": "Convert namespace import to named imports",
                "kind": "refactor.rewrite.import.named",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert named imports to default import",
        "actions": [
            {
                "name": "Convert named imports to default import",
                "description": "Convert named imports to default import",
                "kind": "refactor.rewrite.import.default",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Convert import",
        "description": "Convert named imports to namespace import",
        "actions": [
            {
                "name": "Convert named imports to namespace import",
                "description": "Convert named imports to namespace import",
                "kind": "refactor.rewrite.import.namespace",
                "notApplicableReason": "Selection is not an import declaration."
            }
        ]
    },
    {
        "name": "Extract type",
        "description": "Extract type",
        "actions": [
            {
                "name": "Extract to typedef",
                "description": "Extract to typedef",
                "kind": "refactor.extract.typedef",
                "notApplicableReason": "Selection is not a valid type node"
            },
            {
                "name": "Extract to type alias",
                "description": "Extract to type alias",
                "kind": "refactor.extract.type",
                "notApplicableReason": "Selection is not a valid type node"
            },
            {
                "name": "Extract to interface",
                "description": "Extract to interface",
                "kind": "refactor.extract.interface",
                "notApplicableReason": "Selection is not a valid type node"
            }
        ]
    },
    {
        "name": "Move to file",
        "description": "Move to file",
        "actions": [
            {
                "name": "Move to file",
                "description": "Move to file",
                "kind": "refactor.move.file",
                "range": {
                    "start": {
                        "line": 10,
                        "offset": 1
                    },
                    "end": {
                        "line": 10,
                        "offset": 15
                    }
                }
            }
        ]
    },
    {
        "name": "Move to a new file",
        "description": "Move to a new file",
        "actions": [
            {
                "name": "Move to a new file",
                "description": "Move to a new file",
                "kind": "refactor.move.newFile",
                "range": {
                    "start": {
                        "line": 10,
                        "offset": 1
                    },
                    "end": {
                        "line": 10,
                        "offset": 15
                    }
                }
            }
        ]
    },
    {
        "name": "Add or remove braces in an arrow function",
        "description": "Add or remove braces in an arrow function",
        "actions": [
            {
                "name": "Add braces to arrow function",
                "description": "Add braces to arrow function",
                "kind": "refactor.rewrite.arrow.braces.add",
                "notApplicableReason": "Could not find a containing arrow function"
            },
            {
                "name": "Remove braces from arrow function",
                "description": "Remove braces from arrow function",
                "kind": "refactor.rewrite.arrow.braces.remove",
                "notApplicableReason": "Could not find a containing arrow function"
            }
        ]
    },
    {
        "name": "Convert to template string",
        "description": "Convert to template string",
        "actions": [
            {
                "name": "Convert to template string",
                "description": "Convert to template string",
                "kind": "refactor.rewrite.string",
                "notApplicableReason": "Can only convert string concatenations and string literals"
            }
        ]
    },
    {
        "name": "Extract Symbol",
        "description": "Extract function",
        "actions": [
            {
                "name": "Extract Function",
                "description": "Extract function",
                "kind": "refactor.extract.function",
                "notApplicableReason": "Cannot extract empty range."
            }
        ]
    },
    {
        "name": "Extract Symbol",
        "description": "Extract constant",
        "actions": [
            {
                "name": "Extract Constant",
                "description": "Extract constant",
                "kind": "refactor.extract.constant",
                "notApplicableReason": "Cannot extract empty range."
            }
        ]
    },
    {
        "name": "Generate 'get' and 'set' accessors",
        "description": "Generate 'get' and 'set' accessors",
        "actions": [
            {
                "name": "Generate 'get' and 'set' accessors",
                "description": "Generate 'get' and 'set' accessors",
                "kind": "refactor.rewrite.property.generateAccessors",
                "notApplicableReason": "Could not find property for which to generate accessor"
            }
        ]
    }
]
```