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

Typescript server crash when using typescript-strict-plugin with Typescript 5.4 #70

Open
guillaumewuip opened this issue Mar 17, 2024 · 8 comments · Fixed by #71 · May be fixed by #74
Open

Typescript server crash when using typescript-strict-plugin with Typescript 5.4 #70

guillaumewuip opened this issue Mar 17, 2024 · 8 comments · Fixed by #71 · May be fixed by #74

Comments

@guillaumewuip
Copy link
Contributor

guillaumewuip commented Mar 17, 2024

Hello there!

I'm using this wonderful plugin on a legacy codebase. We've just migrated to the latest TS 5.4 and text editors typescript integrations are not working anymore (no error reported, no suggestions, etc) (Intellij, VSCode, Neovim).

Here is a minimal repo reproducing the issue: https://github.com/guillaumewuip/typescript-strict-plugin-5.4-bug/blob/main/src/index.ts

I've investigated a bit, and found a potential fix.

Ensuring that we use local TS version (and not the VSCode one), we can find the related log on tsserver side:

    Cannot read properties of undefined (reading 'getSourceFile')

    TypeError: Cannot read properties of undefined (reading 'getSourceFile')
        at getValidSourceFile (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:146234:32)
        at Object.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:146498:30)
        at proxy.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript-strict-plugin@2.4.0/node_modules/typescript-strict-plugin/dist/plugin/index.js:15:38)
Bigger log
Info 78   [14:38:26.196] TIAdapter:: Scheduling request for: /dev/null/inferredProject1*
Info 79   [14:38:26.197] AutoImportProviderProject: found 1 root files in 1 dependencies in 1.1183749996125698 ms
Info 80   [14:38:26.197] Starting updateGraphWorker: Project: /dev/null/autoImportProviderProject2*
Info 81   [14:38:26.237] Finishing updateGraphWorker: Project: /dev/null/autoImportProviderProject2* projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed: 39.96095800027251ms
Info 82   [14:38:26.237] Project '/dev/null/autoImportProviderProject2*' (AutoImportProvider)
Info 83   [14:38:26.237] 	Files (1)
	/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/typescript.d.ts


	node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/typescript.d.ts
	  Root file specified for compilation

Info 84   [14:38:26.237] -----------------------------------------------
Info 85   [14:38:26.238] Project '/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/tsconfig.json' (Configured)
Info 85   [14:38:26.238] 	Files (20)

Info 85   [14:38:26.238] -----------------------------------------------
Info 85   [14:38:26.238] Project '/dev/null/autoImportProviderProject1*' (AutoImportProvider)
Info 85   [14:38:26.238] 	Files (1)

Info 85   [14:38:26.238] -----------------------------------------------
Info 85   [14:38:26.238] Project '/dev/null/inferredProject1*' (Inferred)
Info 85   [14:38:26.238] 	Files (55)

Info 85   [14:38:26.238] -----------------------------------------------
Info 85   [14:38:26.238] Project '/dev/null/autoImportProviderProject2*' (AutoImportProvider)
Info 85   [14:38:26.238] 	Files (1)

Info 85   [14:38:26.238] -----------------------------------------------
Info 85   [14:38:26.238] Open files: 
Info 85   [14:38:26.238] 	FileName: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts ProjectRootPath: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug
Info 85   [14:38:26.238] 		Projects: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/tsconfig.json
Info 85   [14:38:26.238] 	FileName: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript-strict-plugin@2.4.0/node_modules/typescript-strict-plugin/dist/plugin/index.js ProjectRootPath: /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug
Info 85   [14:38:26.238] 		Projects: /dev/null/inferredProject1*
Perf 85   [14:38:26.238] 2::updateOpen: elapsed time (in milliseconds) 493.6265
Info 86   [14:38:26.238] response:
    {"seq":0,"type":"response","command":"updateOpen","request_seq":2,"success":true,"performanceData":{"updateGraphDurationMs":460.96408300101757,"createAutoImportProviderProgramDurationMs":104.01749899610877},"body":true}
Info 87   [14:38:26.238] request:
    {
      "seq": 3,
      "type": "request",
      "command": "geterr",
      "arguments": {
        "delay": 0,
        "files": [
          "/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts",
          "/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript-strict-plugin@2.4.0/node_modules/typescript-strict-plugin/dist/plugin/index.js"
        ]
      }
    }
Perf 88   [14:38:26.239] 3::geterr: async elapsed time (in milliseconds) 0.2479
Info 89   [14:38:26.240] event:
    {"seq":0,"type":"event","event":"syntaxDiag","body":{"file":"/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/src/index.ts","diagnostics":[]}}
Err 90    [14:38:26.247] Exception on executing command delayed processing of request 3:

    Cannot read properties of undefined (reading 'getSourceFile')

    TypeError: Cannot read properties of undefined (reading 'getSourceFile')
        at getValidSourceFile (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:146234:32)
        at Object.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:146498:30)
        at proxy.getSemanticDiagnostics (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript-strict-plugin@2.4.0/node_modules/typescript-strict-plugin/dist/plugin/index.js:15:38)
        at IpcIOSession.semanticCheck (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:185769:125)
        at /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:185830:14
        at MultistepOperation.executeAction (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:184479:9)
        at /Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:184452:71
        at IpcIOSession.executeWithRequestId (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:187516:14)
        at Object.executeWithRequestId (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:185514:57)
        at Immediate._onImmediate (/Users/g.clochard/Downloads/typescript-strict-plugin-5.4-bug/node_modules/.pnpm/typescript@5.4.2/node_modules/typescript/lib/tsserver.js:184452:28)
        at process.processImmediate (node:internal/timers:480:21)
Info 91   [14:38:26.247] event:
    {"seq":0,"type":"event","event":"requestCompleted","body":{"request_seq":3}}

This validate that typescript-strict-plugin is probably the culprit.

When calling TS getSemanticDiagnostics here, it leads to a error thrown from typescript language service instance itself: Cannot read properties of undefined (reading 'getSourceFile')

Looking inside typescript code, we understand this means that the program variable is undefined here. Looks like it’s not initialized (anymore?)when the language service instance is created, but only when some methods like are called.

Calling getProgram just after language service instance initialization fixes the issue.

 const strictLanguageService = typescript.createLanguageService(strictLanguageServiceHost);
+strictLanguageService.getProgram()

Is this a valid fix from your point of view? I will push a PR for that - please don't hesitate to redirect me to a better fix if needed, thanks!

@km-tr
Copy link

km-tr commented Apr 23, 2024

@guillaumewuip
I feel like this issue is still occurring, what do you think?

@kamkry
Copy link
Collaborator

kamkry commented Apr 25, 2024

I agree, it seems like the issue is still present

@kamkry
Copy link
Collaborator

kamkry commented Apr 25, 2024

Could you try version 2.4.2-beta.0? @km-tr

@km-tr
Copy link

km-tr commented Apr 25, 2024

@kamkry I tried what you suggested, but just like before, no errors seem to be displayed in TS 5.4.

@kamkry
Copy link
Collaborator

kamkry commented Apr 26, 2024

@km-tr could you please share the minimal reproducible example? The new version seems to fix the problem from this issue.

@km-tr
Copy link

km-tr commented Apr 26, 2024

@kamkry Sure, I'll prepare it after work, so please give me a little time.

@KostkaBrukowa
Copy link
Collaborator

For reproducible example you can take a look at #75 this PR. I've bring back e2e tests and they fail on 5.4.5 version

@KostkaBrukowa
Copy link
Collaborator

@km-tr can you try 2.4.2-beta.1?

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