/cursor-tutorials

How to fix broken imports from Cursor

Learn how to fix broken imports from Cursor with simple steps that restore smooth workflow, improve code reliability, and prevent errors.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to fix broken imports from Cursor

When Cursor “breaks your imports,” the fastest real fix is to manually verify your import paths and file structure yourself, then use Cursor only to assist, not to assume it’s right. Cursor can rewrite imports incorrectly because it doesn’t always know your folder layout or TypeScript/Node/Python resolution rules. The fix is always the same: check the real file paths on disk, confirm the correct relative or absolute import style, adjust tsconfig / webpack / Python path settings if needed, and then run your project locally to verify. Treat Cursor like an assistant that proposes changes, not an authority that edits blindly.

 

Why Cursor Breaks Imports

 

Sometimes Cursor “thinks” a file lives in a different folder, or it rewrites imports to be shorter/cleaner but ignores your real project settings. It also can hallucinate that certain alias paths exist (like @/utils) even if your tsconfig.json doesn’t define them or your bundler doesn’t support them.

  • Cursor doesn’t read your filesystem perfectly unless you select the exact files.
  • Refactors can move files and Cursor forgets to update all related imports.
  • Alias imports might be “imagined” even if not configured.

 

The Reliable Fix (step-by-step)

 

This is the exact process senior devs follow so imports don’t break whenever Cursor edits multiple files.

  • Open the terminal inside Cursor and run your normal dev command (like npm run dev, node index.js, python app.py). The terminal is the truth — it shows real errors.
  • Read the error message about which file import failed. Example:
Error: Cannot find module '../utils/formatDate'
  • Go to your file tree and check what the real path is. Maybe the folder is helpers, not utils.
  • Fix the path manually. Example in Node/React:
// Incorrect (what Cursor sometimes writes)
import formatDate from '../utils/formatDate'

// Correct (matches real folder on disk)
import formatDate from '../helpers/formatDate.js'
  • For TypeScript path aliases (like @/components), verify they actually exist in tsconfig.json:
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]   // Must match actual folder!
    }
  }
}
  • If they don’t exist, either add them or stop using the alias.
  • In Python, verify that the folder has an **init**.py or that you’re running the script from the correct location so relative imports work.
# Correct Python import if structure is:
# app/
#   utils/
#     __init__.py
#     math_tools.py

from app.utils.math_tools import calculate
  • Run your code again to confirm the import works.
  • OPTIONALLY let Cursor help after you know the correct path. For example, write in a Chat tab: “Update all imports referencing ../utils/formatDate to ../helpers/formatDate.js.” Cursor can then apply that consistently.

 

How to Prevent Cursor From Breaking Imports in the Future

 

These habits eliminate 90% of future pain.

  • Always show Cursor the real folder structure when asking for changes. Select the files or press “+ Add Files.”
  • After a big refactor, run your dev server immediately to catch broken paths early.
  • Use your IDE’s built-in import tools (auto-import, quick fix) instead of letting Cursor rewrite everything.
  • Lock down your path aliases in tsconfig.json or Python project structure so Cursor can’t guess incorrectly.

 

Quick Example of a Correct Fix

 

If Cursor rewrote this:

import { calculateTotal } from '@/lib/math'

But your project actually has:

src/utils/math.js

The correct import is:

import { calculateTotal } from '../utils/math.js'

Or, if you want aliases:

// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@/*": ["*"]
    }
  }
}

Then your original alias import becomes valid.

 

The real fix is always the same: trust your filesystem and runtime errors, not Cursor’s guesses. Use Cursor to help you make consistent changes only after you’ve confirmed what the correct import should be.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022