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
- Verify the path with fs.existsSync/isDirectory before calling and correct typos.
- Pass the directory, not a file, when adding a workspace root.
- Expand user home/variables yourself (or confirm coc's expand handles them) so the resolved path exists.
- 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
- statSync().isDirectory() every user-supplied path before adding
- Use fs.realpathSync to normalize symlinks and casing
- Validate config paths at startup and warn early
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
- Invalid dest path: ${dest}
- ${dest} exists, but not directory!
- name and doComplete required for createSource
- Required root pattern not resolved.
- Feature param could only starts with nvim and patch
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/765623c453670a90.
Report an issue: GitHub.