Cursor·Fix

Fix: Cursor References Functions or APIs That Don't Exist

Quick Answer

Always include the actual file with @file before asking Cursor to modify it. After generation, run your TypeScript compiler immediately — tsc --noEmit catches hallucinated function names instantly.

Quick Fix Summary

IssueHallucinating functions that dont exist
Fastest fixInclude source files with @file
Use this page ifGenerated code calls functions that don't exist in your codebase

Symptoms

  • !Generated code calls functions that don't exist in your codebase
  • !Import statements reference modules you never created
  • !API method names look plausible but are completely wrong
  • !TypeScript shows 'Property does not exist' errors everywhere

Step-by-Step Fix

1

Include source files with @file

Before asking Cursor to use a function, include the file where it's defined: @src/lib/utils.ts 'use the formatDate function in the dashboard'. This forces the AI to reference real code.

2

Run TypeScript immediately after generation

After Cursor generates code, run: npx tsc --noEmit. Every hallucinated import or function call will show as a TypeScript error. Fix them before moving on.

3

Ask Cursor to check itself

After generating code, ask: 'Check that every function call in this file actually exists in the codebase. List any that might be hallucinated.' The AI can often catch its own mistakes.

4

Use Composer with @codebase

Composer with @codebase enabled produces fewer hallucinations because it has full project context. Single-file chat mode hallucinates more.

Frequently Asked Questions

The AI generates code based on patterns it learned during training, not your actual codebase. If it hasn't seen your specific files, it guesses — and sometimes guesses wrong.

Always include relevant files with @file, use @codebase for complex tasks, and run TypeScript checking after every generation. Hallucinations drop by 90% with proper context.

Related

Weekly Signals

Get the next fix, switch, or warning before it hits your build.

Join builders getting the community signals, fix patterns, and tool shifts that matter before they show up everywhere else.

Follow the signals →