Cursor Using APIs That Don't Exist
Quick Answer
The AI generates code based on patterns from training data, not your actual codebase. Without proper context, it guesses — and sometimes guesses wrong. Start with "Include source files with @file" before making broader code changes.
You're in the right place if...
- !Generated code calls functions that don't exist
- !Import references modules you never created
- !TypeScript shows 'Property does not exist' errors
Why this happens
The AI generates code based on patterns from training data, not your actual codebase. Without proper context, it guesses — and sometimes guesses wrong.
Fix
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'.
Run TypeScript check
After generation, run:
npx tsc --noEmit # Every hallucinated import shows as a TypeScript error
Tell Cursor to verify
After generating code, ask: 'Check that every function call in this file actually exists in the codebase. List any that might be hallucinated.'
Prevent this next time
Always include relevant files with @file. Use @codebase for complex tasks. Run npx tsc --noEmit after every generation.
Frequently Asked Questions
It generates based on training patterns, not your actual code. Without context, it guesses plausible-looking function names.
Always use @file to include relevant source files. Hallucinations drop by 90% with proper context.
Related fixes
Weekly Newsletter
Get next week's fix before you need it.
Join developers getting weekly vibe coding tips, error fixes, and tool updates.
Subscribe on Substack →