{"record":{"id":"48e9600ee592e9ab","repo":"microsoft/monaco-editor","slug":"renaming-files-is-not-supported","errorCode":null,"errorMessage":"Renaming files is not supported.","messagePattern":"Renaming files is not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/languages/features/typescript/languageFeatures.ts","lineNumber":1185,"sourceCode":"\t\tconst offset = model.getOffsetAt(position);\n\t\tconst worker = await this._worker(resource);\n\n\t\tif (model.isDisposed()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst renameInfo = await worker.getRenameInfo(fileName, offset, {\n\t\t\tallowRenameOfImportPath: false\n\t\t});\n\t\tif (renameInfo.canRename === false) {\n\t\t\t// use explicit comparison so that the discriminated union gets resolved properly\n\t\t\treturn {\n\t\t\t\tedits: [],\n\t\t\t\trejectReason: renameInfo.localizedErrorMessage\n\t\t\t};\n\t\t}\n\t\tif (renameInfo.fileToRename !== undefined) {\n\t\t\tthrow new Error('Renaming files is not supported.');\n\t\t}\n\n\t\tconst renameLocations = await worker.findRenameLocations(\n\t\t\tfileName,\n\t\t\toffset,\n\t\t\t/*strings*/ false,\n\t\t\t/*comments*/ false,\n\t\t\t/*prefixAndSuffix*/ false\n\t\t);\n\n\t\tif (!renameLocations || model.isDisposed()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst edits: languages.IWorkspaceTextEdit[] = [];\n\t\tfor (const renameLocation of renameLocations) {\n\t\t\tconst model = this._libFiles.getOrCreateModel(renameLocation.fileName);\n\t\t\tif (model) {","sourceCodeStart":1167,"sourceCodeEnd":1203,"githubUrl":"https://github.com/microsoft/monaco-editor/blob/ca1b42dc896b99db78e1c743256e8654e12cea2d/src/languages/features/typescript/languageFeatures.ts#L1167-L1203","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rename a symbol inside the file instead of the import path / module specifier.","If you are building a UI on top, pre-check via worker.getRenameInfo and skip/warn the user when renameInfo.fileToRename is defined.","To rename a module, rename the file on disk and update imports manually — Monaco will not do it.","Avoid positioning the cursor on the import path when triggering rename."],"exampleFix":"// before — caller invokes rename at an import path position\nconst result = await editor.getAction('editor.action.rename').run();\n// throws 'Renaming files is not supported.'\n// after — guard before running rename\nconst info = await worker.getRenameInfo(fileName, offset, { allowRenameOfImportPath: false });\nif (info.canRename === true && info.fileToRename !== undefined) {\n  // surface a user-friendly message instead of letting it throw\n  showWarning('File rename is not supported in the editor.');\n} else { /* proceed with rename */ }","handlingStrategy":"validation","validationCode":"const info = await worker.getRenameInfo(fileName, offset, { allowRenameOfImportPath: false });\nif (info.canRename === true && info.fileToRename !== undefined) {\n  // file rename not supported — show user a message, do not call the rename provider\n  showWarning('Renaming files is not supported in the Monaco editor.');\n} else {\n  // safe to proceed with provider.provideRenameEdits\n}","typeGuard":"function isFileRename(info: { canRename: boolean; fileToRename?: string }): boolean {\n  return info.canRename !== false && info.fileToRename !== undefined;\n}","tryCatchPattern":"try {\n  await renameProvider.provideRenameEdits(model, position, newName);\n} catch (e) {\n  if (e instanceof Error && /Renaming files is not supported/.test(e.message)) {\n    informUser('File renames are unsupported; rename a symbol inside the file instead.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Pre-check renameInfo before invoking the rename action when positioning on imports.","Surface a friendly message instead of letting the throw propagate to the user.","Avoid programmatic rename calls at import-path positions."],"tags":["runtime","typescript","rename","refactor","language-services"],"backgroundTag":null,"analyzedSha":"ca1b42dc896b99db78e1c743256e8654e12cea2d","analyzedAt":"2026-08-13T02:00:51.380Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}