question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Server Error (4.5.4): Cannot read property 'close' of undefined

See original GitHub issue

Bug Report

🔎 Search Terms

TS Server Error, TypeScript Server Error, Cannot read property ‘close’ of undefined

🕗 Version & Regression Information

This is an issue I encounter on TypeScript 4.5.4, typescript@next and TypeScript 4.5.3. I only tried these three.

🙁 Actual behavior

Code is irrelevant. When typing, I’m assuming when the server looks for symbols, suddenly the Intellisense stops. When I check the VSC console, I get the following logs:

Details
  ERR <semantic> TypeScript Server Error (4.5.4)
Cannot read property 'close' of undefined
TypeError: Cannot read property 'close' of undefined
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:7578:33)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:112778:29)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:168181:37)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:168197:33)
    at d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:169618:186
    at Map.forEach (<anonymous>)
    at Object.clear (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:169618:142)
    at ConfiguredProject.Project.updateGraphWorker (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:165117:47)
    at ConfiguredProject.Project.updateGraph (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:164962:42)
    at ConfiguredProject.updateGraph (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:165955:63)
    at Object.updateProjectIfDirty (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:166444:45)
    at ConfiguredProject.Project.getLanguageService (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:164576:28)
    at IOSession.Session.getSignatureHelpItems (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:171629:41)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:170410:61)
    at d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172193:88
    at IOSession.Session.executeWithRequestId (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172184:28)
    at IOSession.Session.executeCommand (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172193:33)
    at IOSession.Session.onMessage (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172219:35)
    at Interface.<anonymous> (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174824:31)
    at Interface.emit (events.js:315:20)
    at Interface._onLine (readline.js:337:10)
    at Interface._normalWrite (readline.js:482:12)
    at Socket.ondata (readline.js:194:10)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23): Error: <semantic> TypeScript Server Error (4.5.4)
Cannot read property 'close' of undefined
TypeError: Cannot read property 'close' of undefined
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:7578:33)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:112778:29)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:168181:37)
    at Object.close (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:168197:33)
    at d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:169618:186
    at Map.forEach (<anonymous>)
    at Object.clear (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:169618:142)
    at ConfiguredProject.Project.updateGraphWorker (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:165117:47)
    at ConfiguredProject.Project.updateGraph (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:164962:42)
    at ConfiguredProject.updateGraph (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:165955:63)
    at Object.updateProjectIfDirty (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:166444:45)
    at ConfiguredProject.Project.getLanguageService (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:164576:28)
    at IOSession.Session.getSignatureHelpItems (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:171629:41)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:170410:61)
    at d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172193:88
    at IOSession.Session.executeWithRequestId (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172184:28)
    at IOSession.Session.executeCommand (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172193:33)
    at IOSession.Session.onMessage (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172219:35)
    at Interface.<anonymous> (d:\Programmes\Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174824:31)
    at Interface.emit (events.js:315:20)
    at Interface._onLine (readline.js:337:10)
    at Interface._normalWrite (readline.js:482:12)
    at Socket.ondata (readline.js:194:10)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)
    at Function.create (d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:494353)
    at dispatchResponse (d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:488189)
    at dispatchMessage (d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:487046)
    at d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:486531
    at u.fire (d:\Programmes\Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:66:1712)
    at m.onLengthData (d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:497282)
    at Socket.<anonymous> (d:\Programmes\Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:496929)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)

Restarting the TypeScript server works for a few seconds, and it stops again after a few seconds of typings. For instance, I created a new file where I started to type import, and it crashed. A second time it didn’t crash, but then it crashed when I typed the symbol I imported.

🙂 Expected behavior

It shouldn’t crash when typing.

Reproduction

I’m really not sure how to reproduce this. My only TypeScript project for the moment is https://github.com/preset/preset, and this is the one TypeScript crashes in.

Maybe relevant: I’m using a pnpm monorepository. TypeScript is installed at the root and in every package. I’ve tried VSC’s TypeScript version and the package’s version.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sandersncommented, Feb 1, 2022

The reason I tried signature help was the call to IOSession.Session.getSignatureHelpItems in the stack. The next things to happen were getLanguageService/updateProjectIfDirty, so maybe it behaves differently if you build the project first. I’ll try pnpm run build and then check signature help again.

0reactions
innocenzicommented, Feb 4, 2022

So, I’ve been working on the project again. It took about 15 minutes for me to notice the TypeScript server crashed.

I restarted and tried again: I was working on the config, so packages/core/src/config.ts. I replaced all the code except the imports. I started adding a new function, trying to import the symbol of a package that I just added. It isn’t detected so I add the import, then I save. Before I save, I have this in the file:

import path from 'node:path'
import os from 'node:os'
import fs from 'node:fs'
import { PresetConfiguration } from './types'
import { debug } from './utils'
import { loadConfig } from 'unconfig'

export function initializeConfig() {
	await loadConfig()
}

And when I saved I saw the TS server crash (I had devtools open).

If it’s of any help, here is my extension list:

Details
a5huynh.vscode-ron
alefragnani.project-manager
amiralizadeh9480.laravel-extra-intellisense
amirmarmul.laravel-blade-vscode
antfu.iconify
arcanis.vscode-zipfs
austenc.laravel-docs
austenc.tailwind-docs
be5invis.toml
be5invis.vscode-custom-css
bierner.color-info
bmewburn.vscode-intelephense-client
bmuskalla.vscode-tldr
bradlc.vscode-tailwindcss
BriteSnow.vscode-toggle-quotes
bungcip.better-toml
Cardinal90.multi-cursor-case-preserve
cpylua.language-postcss
dbaeumer.vscode-eslint
DotJoshJohnson.xml
drKnoxy.eslint-disable-snippets
eamodio.gitlens
ecmel.vscode-html-css
emilast.LogFileHighlighter
esbenp.prettier-vscode
firefox-devtools.vscode-firefox-debug
folke.vscode-monorepo-workspace
formulahendry.code-runner
GitHub.copilot
GitHub.remotehub
Gruntfuggly.todo-tree
heybourn.headwind
icrawl.discord-vscode
iocave.monkey-patch
ionutvmi.reg
jock.svg
johnsoncodehk.volar
jolaleye.horizon-theme-vscode
junstyle.php-cs-fixer
Kasik96.latte
kumar-harsh.graphql-for-vscode
lehni.vscode-fix-checksums
m1guelpf.better-pest
me-dutour-mathieu.vscode-github-actions
meganrogge.template-string-converter
MehediDracula.php-namespace-resolver
mikestead.dotenv
mrmlnc.vscode-apache
ms-python.python
ms-python.vscode-pylance
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode.cpptools
ms-vscode.hexeditor
ms-vscode.powershell
naumovs.color-highlight
neilbrayfield.php-docblocker
rebornix.toggle
redhat.vscode-commons
redhat.vscode-yaml
rohit-gohri.format-code-action
rust-lang.rust
ryuta46.multi-command
shufo.vscode-blade-formatter
silvenon.mdx
slevesque.vscode-autohotkey
swordev.phpstan
tinkerun.tinkerun-vscode
tomoki1207.vscode-input-sequence
Tyriar.lorem-ipsum
voorjaar.windicss-intellisense
whatwedo.twig
wmaurer.change-case
yzhang.markdown-all-in-one
znck.preview
znck.vue
znck.vue-language-features

Tell me if I can give you any more useful information

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'close' of undefined" in E2E test - Stack ...
I would like to test my WebSocket, but I have the problem that my test runs into an error and the ...
Read more >
npm err! cannot read properties of undefined (reading 'name')
Solution 1: Clear Cache. First you need to clear your cache by this command: npm cache clear --force. Now, run npm install command....
Read more >
Announcing TypeScript 4.8 - Microsoft Developer Blogs
All existing decorators properties have been marked as deprecated and will always be undefined if read. The type has also been changed to ......
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes ...
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
In Regular Type Check Mode, TypeScript is aware that a function might return undefined . But at the same time, TypeScript infers the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found