Skip to content

finally is not a function error hit with _getServerWorkingDir #1653

Description

@rcjsuen
TypeError this._getServerWorkingDir(...).then(...).finally is not a function 
    extension.js:1:395787 d.createMessageTransports
    extension.js:1:226888 d.createConnection
    extension.js:1:217342 d.start
    extension.js:1:130234 _

private _getServerWorkingDir(options?: { cwd?: string }): Promise<string | undefined> {
let cwd = options && options.cwd;
if (!cwd) {
cwd = this.clientOptions.workspaceFolder
? this.clientOptions.workspaceFolder.uri.fsPath
: this._mainGetRootPath();
}
if (cwd) {
// make sure the folder exists otherwise creating the process will fail
return new Promise(s => {
fs.lstat(cwd!, (err, stats) => {
s(!err && stats.isDirectory() ? cwd : undefined);
});
});
}
return Promise.resolve(undefined);
}

I see this error in the telemetry of our VS Code extension. If I try to search the error on the Internet, I can find a single StackOverflow post talking about the same thing. I have looked at the code and tried writing a small JavaScript program but can't quite figure out in what case this might happen. We are on 9.0.1 of vscode-languageclient.

Activity

  1. dbaeumer commented on Aug 4, 2025

    @dbaeumer
    Member

    Remy Suen (@rcjsuen) is this still an issue for you?

  2. rcjsuen commented on Aug 4, 2025

    @rcjsuen
    ContributorAuthor

    is this still an issue for you?

    Dirk Bäumer (@dbaeumer) Yes. I still see the error every day in our telemetry across all three major operating systems.

  3. dbaeumer commented on Aug 6, 2025

    @dbaeumer
    Member

    I looked at the code and I have honestly no idea what is causing it. Do you know if you do anything special with working directories?

  4. rcjsuen commented on Aug 6, 2025

    @rcjsuen
    ContributorAuthor

    I looked at the code and I have honestly no idea what is causing it. Do you know if you do anything special with working directories?

    No, we don't. The client options code can be found here. The telemetry shows that vscode.env.appHost is "desktop" but my suspicions right now are:

    • strange workspace folder (with some non-standard URI?)
    • no workspace folder
    • says "desktop" but is actually Codespaces or some other custom cloud environment
    • JavaScript packaging/webpack causing promise weirdness

    The StackOverflow post seems to suggest they were hitting it on the JSON language server so even a "standard installation" is triggering it.

    I am getting the following when I open VSCode with a Salesforce Lightening Web Components project.

    I don't understand this bit though and how that would trigger this error...

  5. VoloviZzz commented on Aug 12, 2025

    @VoloviZzz

    I managed to solve the problem only by clearing all vs code files.

    rm -fr ~/Library/Preferences/com.microsoft.VSCode.helper.plist
    rm -fr ~/Library/Preferences/com.microsoft.VSCode.plist
    rm -fr ~/Library/Caches/com.microsoft.VSCode
    rm -fr ~/Library/Caches/com.microsoft.VSCode.ShipIt/
    rm -fr ~/Library/Application\ Support/Code/
    rm -fr ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState/
    rm -fr ~/.vscode/
    rm -rf ~/.vscode*

  6. dbaeumer commented on Dec 9, 2025

    @dbaeumer
    Member

    Could it be that a different Promise libary is used that doesn't have finally.

    I could change the code to use try { } finally { } instead but I would like to understand why it is failing

  7. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    info-neededIssue requires more information from poster
    on Dec 9, 2025
  8. marscosta commented on Jan 2, 2026

    @marscosta

    I managed to solve the problem only by clearing all vs code files.

    rm -fr ~/Library/Preferences/com.microsoft.VSCode.helper.plist rm -fr ~/Library/Preferences/com.microsoft.VSCode.plist rm -fr ~/Library/Caches/com.microsoft.VSCode rm -fr ~/Library/Caches/com.microsoft.VSCode.ShipIt/ rm -fr ~/Library/Application\ Support/Code/ rm -fr ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState/ rm -fr ~/.vscode/ rm -rf ~/.vscode*

    FYI I'm having the exact same problem and these steps solved it for me (even though it deleted all my preferences / extensions). It was blocking several things in my environment.

    My versions:
    Version: 1.107.1
    Commit: 994fd12f8d3a5aa16f17d42c041e5809167e845a
    Date: 2025-12-17T14:15:14.850Z (2 wks ago)
    Electron: 39.2.3
    ElectronBuildId: 12895514
    Chromium: 142.0.7444.175
    Node.js: 22.21.1
    V8: 14.2.231.21-electron.0
    OS: Darwin arm64 24.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions