microsoft/TypeScript · error · Error

No test file named "${indexOrName}" exists. Available file n

Error message

No test file named "${indexOrName}" exists. Available file names are: ${availableNames.join(", ")}

What it means

Thrown by findFile when the string argument to openFile/goTo.file does not match any test file name. The message lists all available file names so the author can correct the reference. Matching is done via tryFindFileWorker after normalising the path.

Source

Thrown at src/harness/fourslashImpl.ts:4436

                this.currentCaretPosition,
            ).line,
        );
    }

    private findFile(indexOrName: string | number): FourSlashFile {
        if (typeof indexOrName === "number") {
            const index = indexOrName;
            if (index >= this.testData.files.length) {
                throw new Error(`File index (${index}) in openFile was out of range. There are only ${this.testData.files.length} files in this test.`);
            }
            else {
                return this.testData.files[index];
            }
        }
        else if (ts.isString(indexOrName)) {
            const { file, availableNames } = this.tryFindFileWorker(indexOrName);
            if (!file) {
                throw new Error(`No test file named "${indexOrName}" exists. Available file names are: ${availableNames.join(", ")}`);
            }
            return file;
        }
        else {
            return ts.Debug.assertNever(indexOrName);
        }
    }

    private tryFindFileWorker(name: string): { readonly file: FourSlashFile | undefined; readonly availableNames: readonly string[]; } {
        name = ts.normalizePath(name);
        // names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName
        name = name.includes("/") ? name : (this.basePath + "/" + name);

        const availableNames: string[] = [];
        const file = ts.forEach(this.testData.files, file => {
            const fn = ts.normalizePath(file.fileName);
            if (fn) {
                if (fn === name) {

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Read the available file names from the error message and copy the exact spelling/path of the intended file.
  2. If the file should exist, add it to the test using the multi-file fourslash syntax (@FileName or a new //// block).
  3. If you used a bare name, try the path relative to basePath, or vice versa, since matching depends on whether the name contains a slash.

Example fix

// before
goTo.file("moduel.ts");
// after — match an available name from the error output
goTo.file("module.ts");
Defensive patterns

Strategy: validation

Validate before calling

function resolveFileName(state: FourSlashTestState, name: string) {
    const known = state.testData.files.map(f => f.fileName);
    if (!known.some(n => n.endsWith(name) || n === name)) {
        throw new Error(`'${name}' not in: ${known.join(", ")}`);
    }
}

Prevention

When it happens

Trigger: Calling goTo.file("missing.ts") where no file with that name (or relative path) was declared in the fourslash test data. tryFindFileWorker normalises the name and, if it has no slash, prepends basePath before searching.

Common situations: Typo in the file name, referencing a file that was renamed/removed, or using a full path when the test stores files under a relative name. Also happens when the name needs a leading slash or directory prefix.

Related errors


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