string to replace was not found in the file
Last verified:
The fix
string to replace was not found in the file: Cursor edited another path, or the file changed. Revert that diff and name the one file to edit.
- 1
Read the path before you accept
The change card names a file. If that path is not the one you asked for, Reject it. Do not Accept and then ask for an undo. Name the two paths in the next message, and say which one must not be edited.
- 2
Restore from the checkpoint if you already accepted
Use the Cursor checkpoint from before that turn, or
git checkout -- pathfor the file it should not have touched. Asking the model to undo usually edits a third file. Do not reset the whole repository unless you mean to drop every uncommitted change. - 3
Point the next turn at one path
Paste the repo-relative path and @-mention that file. Say "edit only this file." If two modules share a basename, open the import that the app actually uses and name the other file as off limits. Do not ask it to keep the copies in sync.
- 4
If the string to replace was not found, re-read the file
The patch does not match disk. Tell it to open that exact path and make one smaller edit against the current contents. Do not tell it to rewrite the file from memory, and do not create a new file with a slightly different name to "start clean."
Why it happens
The diff is applied to the path on the change card, not to whichever tab is focused. Generated apps collect copies: components/Button.tsx and components/ui/button.tsx, lib/supabase.ts and utils/supabase/client.ts, middleware.ts and proxy.ts. The model fuzzy-matches the name from the chat and edits the other one. The file you meant is unchanged, so the original error stays, and the next turn "fixes" a second copy.
When the patch was built against different text than the file it tried to write, the agent reports that the string to replace was not found in the file. That happens if it read one file and wrote another, or the file changed after it was read. Accepting a follow-up that rewrites the whole file from memory is how the session drifts further from what is on disk.
The next error you'll probably hit
Once this is fixed, the usual follow-up is it keeps rewriting the same file. it keeps rewriting the same file: the new error is in code the model added to hide the last one. Revert that diff and paste the original error once.
Prompt to paste back into your AI tool
Paste this above the error.
Stop. You applied an edit to the wrong file, or the tool said the string to replace was not found in the file. The file that should have changed is: <path> Do not edit this file: <other path, or "none"> Do not create a third copy of the module. Do not rewrite the target file from memory. Do not disable lint or types. Do not git reset the whole repository. Do not change files yet if you are not sure which path is imported. 1. State the path you were about to edit, and the import that actually loads the module. 2. If a wrong file was already changed, name that path so I can restore it from the checkpoint. Do not undo it by editing more files. 3. If the string to replace was not found, re-read the target path and propose one smaller edit against the current contents. 4. Wait until I say apply. Then change only the target path.
Common questions
+The open tab is the right file and the error is still there. Why?
The tab is not the path that was written. Check the change card and git status. The edit landed on the other file with a similar name, or it was rejected and nothing was written.
+It says the string to replace was not found, but I can see that text. Why?
The snippet it tried to replace is not in the file it targeted, or the file changed after it was read. Whitespace and a second copy of the function are enough. Make it re-read that path instead of pasting a full-file rewrite.
Related errors
- it keeps rewriting the same fileit keeps rewriting the same file: the new error is in code the model added to hide the last one. Revert that diff and paste the original error once.CursorLovableBoltNext.jsReactOct 14, 2026
- Module not found: Can't resolveModule not found: Can't resolve means the import path or package is not on disk, often after an AI edit. Fix the path or install the package, then restart.CursorLovableBoltTypeScriptNext.jsOct 14, 2026