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

JS/TS language service crash with other TS extensions #2138

Closed
drewbitt opened this issue Aug 26, 2023 · 6 comments
Closed

JS/TS language service crash with other TS extensions #2138

drewbitt opened this issue Aug 26, 2023 · 6 comments
Labels
Fixed Fixed in master branch. Pending production release. upstream

Comments

@drewbitt
Copy link

Describe the bug

Upon opening a .ts file, my TS language service crashes. It does not matter if I use [email protected] in my workplace, VSCode Insider's 5.2.2, or the Typescript Nightly ms-vscode.vscode-typescript-next-5.3.20230821. If I uninstall this Svelte extension, there is no crash.

Err 207   [22:20:54.732] Exception on executing command {
  "seq": 2,
  "type": "request",
  "command": "updateOpen",
  "arguments": {
    "changedFiles": [],
    "closedFiles": [],
    "openFiles": [
      {
        "file": "c:\\Users\\andys-pc\\GitHub\\MyStuff\\Someplice\\src\\lib\\trpc\\types.ts",
        "fileContent": "import type { z } from 'zod';\nimport type { GoalLogSchema } from './routes/goal_logs';\nimport type { GoalSchema } from './routes/goals';\nimport type { IntentionsSchema } from './routes/intentions';\nimport type { OutcomeIntentionSchema, OutcomeSchema } from './routes/outcomes';\n\nexport type Goal = z.infer<typeof GoalSchema>;\nexport type Intention = z.infer<typeof IntentionsSchema>;\nexport type GoalLog = z.infer<typeof GoalLogSchema>;\nexport type Outcome = z.infer<typeof OutcomeSchema>;\nexport type OutcomeIntention = z.infer<typeof OutcomeIntentionSchema>;\n",
        "projectRootPath": "c:\\Users\\andys-pc\\GitHub\\MyStuff\\Someplice",
        "scriptKindName": "TS"
      }
    ]
  }
}:

    hostOrText.readFile is not a function

    TypeError: hostOrText.readFile is not a function
        at readJsonOrUndefined (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:19664:67)
        at readJson (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:19671:10)
        at getPackageJsonInfo (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42852:32)
        at nodeLoadModuleByRelativeName (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42518:46)
        at tryResolve (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42470:25)
        at nodeModuleNameResolverWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42406:14)
        at bundlerModuleNameResolver (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42334:10)
        at Object.resolveModuleName (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:42114:18)
        at resolveSvelteModuleName (c:\Users\andys-pc\.vscode-insiders\extensions\svelte.svelte-vscode-107.10.0\node_modules\typescript-svelte-plugin\dist\src\module-loader.js:99:49)
        at resolveSvelteModuleNameFromCache (c:\Users\andys-pc\.vscode-insiders\extensions\svelte.svelte-vscode-107.10.0\node_modules\typescript-svelte-plugin\dist\src\module-loader.js:148:32)
        at c:\Users\andys-pc\.vscode-insiders\extensions\svelte.svelte-vscode-107.10.0\node_modules\typescript-svelte-plugin\dist\src\module-loader.js:138:20
        at Array.map (<anonymous>)
        at ConfiguredProject2.resolveModuleNameLiterals (c:\Users\andys-pc\.vscode-insiders\extensions\svelte.svelte-vscode-107.10.0\node_modules\typescript-svelte-plugin\dist\src\module-loader.js:132:25)
        at resolveModuleNamesWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:120746:20)
        at resolveModuleNamesReusingOldState (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:120842:14)
        at processImportedModules (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122422:27)
        at findSourceFileWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122152:7)
        at findSourceFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122017:20)
        at processImportedModules (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122446:11)
        at findSourceFileWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122152:7)
        at findSourceFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122017:20)
        at processImportedModules (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122446:11)
        at findSourceFileWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122152:7)
        at findSourceFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122017:20)
        at processImportedModules (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122446:11)
        at findSourceFileWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122152:7)
        at findSourceFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:122017:20)
        at c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:121966:22
        at getSourceFileFromReferenceWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:121935:26)
        at processSourceFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:121964:5)
        at processRootFile (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:121761:5)
        at c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:120508:41
        at forEach (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:2352:22)
        at createProgram (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:120508:5)
        at synchronizeHostData (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:143907:15)
        at Proxy.getProgram (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:143981:5)
        at ConfiguredProject2.updateGraphWorker (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:176966:41)
        at ConfiguredProject2.updateGraph (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:176817:32)
        at ConfiguredProject2.updateGraph (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:178072:24)
        at _ProjectService.createLoadAndUpdateConfiguredProject (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:179691:13)
        at _ProjectService.assignProjectToOpenedScriptInfo (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:180782:26)
        at c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:181062:64
        at flatMap (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:2600:17)
        at _ProjectService.applyChangesInOpenFiles (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:181062:24)
        at updateOpen (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:182242:29)
        at c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:184838:69
        at IpcIOSession.executeWithRequestId (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:184830:14)
        at IpcIOSession.executeCommand (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:184838:29)
        at IpcIOSession.onMessage (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:184880:51)
        at process.<anonymous> (c:\Users\andys-pc\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:186461:14)
        at process.emit (node:events:513:28)
        at emit (node:internal/child_process:937:14)
        at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

Starts at resolveSvelteModuleName

Reproduction

VSCode Insiders 1.82.0-insider
Svelte for VS Code v107.10.0
A svelte project with a .ts file open to start the language server

Expected behaviour

No crashing of the language server

System Info

Windows 10
VSCode Insiders 1.82.0-insider

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

@drewbitt drewbitt added the bug Something isn't working label Aug 26, 2023
@jasonlyu123
Copy link
Member

I can't reproduce this following your "Reproduction". Please provide reproduction in a repository form.

@drewbitt
Copy link
Author

drewbitt commented Aug 26, 2023

Sorry you weren't happy with my "reproduction". I'm trying to narrow this down to a repro but unsuccessful currently.

It is related to microsoft/TypeScript#51644 in Typescript > 4.9. But it has just suddenly appeared for me, so working out why.

@jasonlyu123
Copy link
Member

Does this happen to all your projects, or is it only a specific one? Maybe it's caused by another extension. What happens if you disable all other extensions? You can create an empty settings profile so it's easier to switch back.

@drewbitt
Copy link
Author

The problem goes away if Svelte for VS Code is the only enabled extension effecting the TS language server. If I enable another one that does hook to the TS language server, like Imba's scrimba.vsimba, the language server crashes every time in certain projects and not in others. Having either enabled by itself does not crash and the crash and the traceback suggests the crash is in Svelte for VS Code.

I'll take a deeper look later this week. For now, I can disable scrimba.vsimba and leave Svelte for VS Code as the only running TS Server extension.

@jasonlyu123
Copy link
Member

jasonlyu123 commented Aug 27, 2023

They use Object.defineProperty to patch typescript's APIs, making readFile not enumerable. So when we are copying the object, the readFile method is not copied. I don't think this should be fixed on our side.

Edit. I changed my mind. It's easier to just define it manually than argue with them to not do this.

@jasonlyu123 jasonlyu123 added upstream and removed bug Something isn't working awaiting submitter labels Aug 27, 2023
@jasonlyu123 jasonlyu123 added the Fixed Fixed in master branch. Pending production release. label Aug 27, 2023
@drewbitt drewbitt changed the title JS/TS language service crash with extension enabled in latest VSCode Insider JS/TS language service crash with other TS extensions Aug 29, 2023
@drewbitt
Copy link
Author

Great! I think that's a smart move so that this conversation isn't just repeated in the future.

Installed extension from location and set svelte.language-server.ls-path - the language sever no longer crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed Fixed in master branch. Pending production release. upstream
Projects
None yet
Development

No branches or pull requests

2 participants