microsoft/monaco-editor · error · Error

Renaming files is not supported.

Error message

Renaming files is not supported.

What it means

Thrown by the TypeScript rename provider when the tsserver rename info indicates the rename target is a whole file (renameInfo.fileToRename is set) rather than a symbol within a file. Monaco's rename API only supports renaming identifiers; renaming a module file (e.g. renaming an import path that resolves to renaming the file itself) is not implemented in the editor, so it throws rather than silently no-op. The check happens after confirming the rename is allowed (canRename !== false) and before computing rename locations.

Source

Thrown at src/languages/features/typescript/languageFeatures.ts:1185

		const offset = model.getOffsetAt(position);
		const worker = await this._worker(resource);

		if (model.isDisposed()) {
			return;
		}

		const renameInfo = await worker.getRenameInfo(fileName, offset, {
			allowRenameOfImportPath: false
		});
		if (renameInfo.canRename === false) {
			// use explicit comparison so that the discriminated union gets resolved properly
			return {
				edits: [],
				rejectReason: renameInfo.localizedErrorMessage
			};
		}
		if (renameInfo.fileToRename !== undefined) {
			throw new Error('Renaming files is not supported.');
		}

		const renameLocations = await worker.findRenameLocations(
			fileName,
			offset,
			/*strings*/ false,
			/*comments*/ false,
			/*prefixAndSuffix*/ false
		);

		if (!renameLocations || model.isDisposed()) {
			return;
		}

		const edits: languages.IWorkspaceTextEdit[] = [];
		for (const renameLocation of renameLocations) {
			const model = this._libFiles.getOrCreateModel(renameLocation.fileName);
			if (model) {

View on GitHub (pinned to ca1b42dc89)

Solutions

  1. Rename a symbol inside the file instead of the import path / module specifier.
  2. If you are building a UI on top, pre-check via worker.getRenameInfo and skip/warn the user when renameInfo.fileToRename is defined.
  3. To rename a module, rename the file on disk and update imports manually — Monaco will not do it.
  4. Avoid positioning the cursor on the import path when triggering rename.

Example fix

// before — caller invokes rename at an import path position
const result = await editor.getAction('editor.action.rename').run();
// throws 'Renaming files is not supported.'
// after — guard before running rename
const info = await worker.getRenameInfo(fileName, offset, { allowRenameOfImportPath: false });
if (info.canRename === true && info.fileToRename !== undefined) {
  // surface a user-friendly message instead of letting it throw
  showWarning('File rename is not supported in the editor.');
} else { /* proceed with rename */ }
Defensive patterns

Strategy: validation

Validate before calling

const info = await worker.getRenameInfo(fileName, offset, { allowRenameOfImportPath: false });
if (info.canRename === true && info.fileToRename !== undefined) {
  // file rename not supported — show user a message, do not call the rename provider
  showWarning('Renaming files is not supported in the Monaco editor.');
} else {
  // safe to proceed with provider.provideRenameEdits
}

Type guard

function isFileRename(info: { canRename: boolean; fileToRename?: string }): boolean {
  return info.canRename !== false && info.fileToRename !== undefined;
}

Try / catch

try {
  await renameProvider.provideRenameEdits(model, position, newName);
} catch (e) {
  if (e instanceof Error && /Renaming files is not supported/.test(e.message)) {
    informUser('File renames are unsupported; rename a symbol inside the file instead.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: User triggers a rename (F2) on an import specifier or module path that tsserver treats as a file rename target; renaming a default-exported module's filename via its import; attempting to rename a path segment that maps to a file on disk.

Common situations: A user presses F2 on an import line expecting to refactor the module name; programmatic call to the rename provider with a position inside an import path; a higher-level refactor tool that doesn't pre-filter file-rename cases.

Related errors


AI-assisted analysis of microsoft/monaco-editor@ca1b42dc89 (2026-08-13). Data as JSON: /api/errors/48e9600ee592e9ab. Report an issue: GitHub.