microsoft/TypeScript · error · Error

Project '${project.getProjectName()}' does not contain docum

Error message

Project '${project.getProjectName()}' does not contain document '${fileName}'

What it means

Thrown via Errors.ThrowProjectDoesNotContainDocument(fileName, project) (utilitiesPublic.ts:65), called from project.ts:1927. It indicates that a request was routed to a specific Project whose script-info set does not contain the requested file — the project and the file are associated incorrectly.

Source

Thrown at src/server/utilitiesPublic.ts:65

        fileNames: project.getFileNames(/*excludeFilesFromExternalLibraries*/ true, /*excludeConfigFiles*/ true).concat(project.getExcludedFiles() as NormalizedPath[]),
        compilerOptions: project.getCompilationSettings(),
        typeAcquisition,
        unresolvedImports,
        projectRootPath: project.getCurrentDirectory() as Path,
        cachePath,
        kind: "discover",
    };
}

export namespace Errors {
    export function ThrowNoProject(): never {
        throw new Error("No Project.");
    }
    export function ThrowProjectLanguageServiceDisabled(): never {
        throw new Error("The project's language service is disabled.");
    }
    export function ThrowProjectDoesNotContainDocument(fileName: string, project: Project): never {
        throw new Error(`Project '${project.getProjectName()}' does not contain document '${fileName}'`);
    }
}

export type NormalizedPath = string & { __normalizedPathTag: any; };

export function toNormalizedPath(fileName: string): NormalizedPath {
    return normalizePath(fileName) as NormalizedPath;
}

export function normalizedPathToPath(normalizedPath: NormalizedPath, currentDirectory: string, getCanonicalFileName: (f: string) => string): Path {
    const f = isRootedDiskPath(normalizedPath) ? normalizedPath : getNormalizedAbsolutePath(normalizedPath, currentDirectory);
    return getCanonicalFileName(f) as Path;
}

export function asNormalizedPath(fileName: string): NormalizedPath {
    return fileName as NormalizedPath;
}

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Re-resolve the owning project via ProjectService.getProjectForFile(fileName) instead of reusing a stale Project handle.
  2. Confirm the fileName (absolute, normalized, correct case) matches a path in project.getFileNames().
  3. If the file was moved/renamed, refresh script-info before retrying.
  4. Handle the case where the file legitimately belongs to a different project and route the request there.

Example fix

// before — using a stale project handle
const project = lastKnownProject; // may be wrong after reload
project.getLanguageService().getQuickInfoAtPosition(fileName, 0);
// throws: Project '...' does not contain document '...'

// after — resolve the owning project fresh
const project = projectService.getProjectForFile(fileName)
  ?? Errors.ThrowNoProject();
project.getLanguageService().getQuickInfoAtPosition(fileName, 0);
Defensive patterns

Strategy: validation

Validate before calling

// Re-resolve the owning project and verify containment before routing the request.
function owningProjectForFile(projectService: ProjectService, fileName: string): Project {
  const project = projectService.getProjectForFile(fileName as NormalizedPath);
  if (!project || !project.containsFile(fileName as NormalizedPath)) {
    throw new Error(`${fileName} is not contained by its resolved project; refresh script-info.`);
  }
  return project;
}

Type guard

function projectContainsFile(project: Project, fileName: string): boolean {
  return project.containsFile(fileName as NormalizedPath);
}

Prevention

When it happens

Trigger: A caller resolves a Project handle (e.g. via a stale config or cross-project lookup) and then asks it for a document it never owned. Common in project.ts paths that assert containment before serving a request; the file may belong to a different project or to no project at all.

Common situations: Using a cached/stale project reference after a reload; cross-project operations (e.g. a shared file referenced from two projects) routed to the wrong one; a file that was removed from the project's include; case/path mismatch between the request and the project's internal paths.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/77afaa89f4342f75. Report an issue: GitHub.