neoclide/coc.nvim · error
Required root pattern not resolved.
Error message
Required root pattern not resolved.
What it means
For language servers that declare a required root pattern (requireRootPattern), coc must locate a workspace root by matching rootPatterns (e.g. package.json, .git) starting from the document's directory. If no pattern is found anywhere up the tree, resolveRoot throws because the server cannot be started without a valid workspace root.
Source
Thrown at src/core/documents.ts:200
public detach(): void {
this._attached = false
for (let bufnr of this.buffers.keys()) {
this.onBufUnload(bufnr)
}
}
public resolveRoot(rootPatterns: string[], requireRootPattern = false): string | undefined {
let doc = this.getDocument(this.bufnr)
let resolved: string | undefined
if (doc && doc.schema == 'file') {
let dir = path.dirname(URI.parse(doc.uri).fsPath)
resolved = resolveRoot(dir, rootPatterns, this.cwd)
} else {
resolved = resolveRoot(this.cwd, rootPatterns)
}
if (requireRootPattern && !resolved) {
throw new Error(`Required root pattern not resolved.`)
}
return resolved
}
public get textDocuments(): LinesTextDocument[] {
let docs: LinesTextDocument[] = []
for (let b of this.buffers.values()) {
if (b.attached) docs.push(b.textDocument)
}
return docs
}
public getDocument(uri: number | string, caseInsensitive = platform.isWindows || platform.isMacintosh): Document | null | undefined {
if (typeof uri === 'number') {
return this.buffers.get(uri)
}
let u = URI.parse(uri)
uri = u.toString()View on GitHub (pinned to 50e974d969)
Solutions
- Open the file inside a project containing a root pattern (e.g. .git, package.json)
- Add/relax rootPatterns in coc settings for that language server, or unset requireRootPattern
- Use :CocOpenLog / workspace.rootPatterns to debug which patterns are searched
- Create a minimal root marker (e.g. empty .git or the configured pattern file) in the directory
Example fix
// before (coc-settings.json)
"tsserver": { "requireRootPattern": true }
// after
"tsserver": { "requireRootPattern": false, "rootPatterns": ["tsconfig.json", ".git"] } Defensive patterns
Strategy: fallback
Validate before calling
// before opening the file, confirm a root pattern exists
const fs = require('fs'); const path = require('path')
let dir = path.dirname(file)
while (true) {
if (['.git','package.json','tsconfig.json'].some(p => fs.existsSync(path.join(dir, p)))) break
const parent = path.dirname(dir); if (parent === dir) { notify('no workspace root found'); break }
dir = parent
} Try / catch
try {
await workspace.openTextDocument(uri)
} catch (e) {
if (String(e.message).includes('root pattern')) notify('Open this file inside a project folder')
else throw e
} Prevention
- Set sensible rootPatterns for each language server in coc-settings.json
- Avoid requireRootPattern:true unless the server truly needs a project root
- Keep project marker files (.git, package.json) present in your workspaces
- Use workspace.folder/workspace.root to confirm detection before opening files
When it happens
Trigger: Opening a file covered by a language server whose configuration sets requireRootPattern:true while the file lives outside any directory containing the configured rootPatterns.
Common situations: Opening a stray .ts file in a temp dir with tsserver configured with required roots; single-file editing outside a project; wrong rootPatterns configured for the language server.
Related errors
- Unexpected messageDialogKind: ${this.messageDialogKind}
- Unexpected messageReportKind: ${msgReportKind}
- coc.nvim requires Node.js VM modules support for ESM extensi
- Unable to load extension at ${extensionRoot}, missing packag
- Unable to load extension at ${filepath}
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/6fa2fc5bfd74c3e5.
Report an issue: GitHub.