neoclide/coc.nvim · error · Error

Directory ${folder} not exists

Error message

Directory ${folder} not exists

What it means

After string validation, addWorkspaceFolder expands the path (supporting ~ and variables) and checks that it is an existing directory via isDirectory; a nonexistent path or a file path throws directoryNotExists with the message "Directory <folder> not exists".

Source

Thrown at src/handler/workspace.ts:182

  }

  public async renameCurrent(): Promise<void> {
    let { nvim } = this
    let oldPath = await nvim.call('coc#util#get_fullpath', []) as string
    let newPath = await callAsync(nvim, 'input', ['New path: ', oldPath, 'file']) as string
    newPath = newPath.trim()
    if (newPath === oldPath || !newPath) return
    if (oldPath.toLowerCase() != newPath.toLowerCase() && fs.existsSync(newPath)) {
      let overwrite = await window.showPrompt(`${newPath} exists, overwrite?`)
      if (!overwrite) return
    }
    await workspace.renameFile(oldPath, newPath, { overwrite: true })
  }

  public addWorkspaceFolder(folder: string): void {
    if (!Is.string(folder)) throw TypeError(`folder should be string`)
    folder = workspace.expand(folder)
    if (!isDirectory(folder)) throw directoryNotExists(folder)
    workspace.workspaceFolderControl.addWorkspaceFolder(folder, true)
  }

  public removeWorkspaceFolder(folder: string): void {
    if (!Is.string(folder)) throw TypeError(`folder should be string`)
    folder = workspace.expand(folder)
    if (!isDirectory(folder)) throw directoryNotExists(folder)
    workspace.workspaceFolderControl.removeWorkspaceFolder(folder)
  }

  public async bufferCheck(): Promise<void> {
    let doc = await workspace.document
    if (!doc.attached) {
      await window.showDialog({
        title: 'Buffer check result',
        content: `Document not attached, ${doc.notAttachReason}`,
        highlight: 'WarningMsg'
      })

View on GitHub (pinned to 50e974d969)

Solutions

  1. Verify the path with fs.existsSync/isDirectory before calling and correct typos.
  2. Pass the directory, not a file, when adding a workspace root.
  3. Expand user home/variables yourself (or confirm coc's expand handles them) so the resolved path exists.
  4. Remove or update stale workspace-folder config entries pointing to deleted folders.

Example fix

// before
workspace.addWorkspaceFolder('~/projcts/app')
// after
const p = require('path').join(require('os').homedir(), 'projects', 'app')
if (require('fs').statSync(p).isDirectory()) workspace.addWorkspaceFolder(p)
Defensive patterns

Strategy: validation

Validate before calling

const st = fs.statSync(folder, { throwIfNoEntry: false })
if (!st || !st.isDirectory()) throw new Error(`Directory does not exist: ${folder}`)

Try / catch

try { workspace.addWorkspaceFolder(folder) } catch (e) { if (String(e).includes('not exists')) { /* prompt user for a valid directory */ } else throw e }

Prevention

When it happens

Trigger: Calling workspace.addWorkspaceFolder with a path that does not exist on disk, points to a file instead of a directory, or contains an unexpanded variable that expands to nothing.

Common situations: Typo in the configured workspace folder path; path valid on a remote/WSL host but not locally; passing a file path instead of the containing directory; stale config after the folder was deleted or renamed.

Related errors


AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31). Data as JSON: /api/errors/765623c453670a90. Report an issue: GitHub.