microsoft/TypeScript · error · Error

No script with name '" + fileName + "'

Error message

No script with name '" + fileName + "'

What it means

Thrown by LanguageServiceAdapterHost.editScript (harnessLanguageService.ts:335) when no ScriptInfo is registered for the given fileName. editScript is meant to mutate an already-known file; if getScriptInfo returns falsy the harness refuses to fabricate one.

Source

Thrown at src/harness/harnessLanguageService.ts:335

            const newFileName = updater(key);
            if (newFileName !== undefined) {
                this.scriptInfos.delete(key);
                this.scriptInfos.set(newFileName, scriptInfo);
                scriptInfo.fileName = newFileName;
            }
        });
    }

    public editScript(fileName: string, start: number, end: number, newText: string): void {
        const script = this.getScriptInfo(fileName);
        if (script) {
            script.editContent(start, end, newText);
            this.vfs.mkdirpSync(vpath.dirname(fileName));
            this.vfs.writeFileSync(fileName, script.content);
            return;
        }

        throw new Error("No script with name '" + fileName + "'");
    }

    public openFile(_fileName: string, _content?: string, _scriptKindName?: string): void {/*overridden*/}

    /**
     * @param line 0 based index
     * @param col 0 based index
     */
    public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
        const script: ScriptInfo = this.getScriptInfo(fileName)!;
        assert.isOk(script);
        return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position);
    }

    public lineAndCharacterToPosition(fileName: string, lineAndCharacter: ts.LineAndCharacter): number {
        const script: ScriptInfo = this.getScriptInfo(fileName)!;
        assert.isOk(script);
        return ts.computePositionOfLineAndCharacter(script.getLineMap(), lineAndCharacter.line, lineAndCharacter.character);

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Register the file first: `host.openFile(fileName, content)` or `addScript(fileName, ScriptSnapshot.fromString(content), /*version*/ "0")`.
  2. Verify the fileName passed to editScript is byte-identical (slashes, case, absolute path) to the one used at registration.
  3. If the file lives in a different host/project, route the edit through that host.
  4. Add an assertion in test setup that getScriptInfo(fileName) is truthy before editScript.

Example fix

// before
host.editScript("/a.ts", 0, 0, "export const x = 1;\n");
// throws: No script with name '/a.ts'

// after — register first
host.openScript("/a.ts", "");
host.editScript("/a.ts", 0, 0, "export const x = 1;\n");
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the script exists before editing.
if (!host.getScriptInfo(fileName)) {
  throw new Error(`Cannot edit unregistered script: ${fileName}. Call openScript/addScript first.`);
}
host.editScript(fileName, start, end, newText);

Type guard

function scriptIsRegistered(host: LanguageServiceHost, fileName: string): boolean {
  return !!host.getScriptInfo(fileName);
}

Prevention

When it happens

Trigger: A test calls `host.editScript("/path/a.ts", start, end, text)` without first adding the file via addScript/openFile, or uses a fileName whose casing/path does not exactly match the registered one.

Common situations: Forgetting the setup `openFile`/`addScript` step; using forward vs back slashes inconsistently; case mismatch on a case-sensitive VFS; editing a file that was added to a different host instance.

Related errors


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