File import errors in Lovable projects are caused by wrong paths, missing exports, circular dependencies, and case sensitivity mismatches. Fix them by using the @/ path alias for all imports, ensuring every component has a matching export statement, checking for circular dependency chains, and verifying that file and import casing match exactly. Lovable's Vite setup supports the @/ alias that maps to src/, so never use relative paths like ../../.
Why file imports fail in Lovable projects
Lovable projects use TypeScript with Vite, which has a specific module resolution system. The @/ path alias is configured in both tsconfig.json and vite.config.ts to map to the src/ directory. When imports break, it is usually because the path does not match the actual file location, the export does not match the import syntax, or a circular dependency creates an undefined import. Case sensitivity is a subtle but common cause. macOS file systems are case-insensitive by default (UserProfile.tsx and userprofile.tsx are the same file), but Linux servers and GitHub are case-sensitive. An import that works locally can fail after deployment if the casing does not match exactly. Circular dependencies happen when file A imports from file B, which imports from file C, which imports from file A. This creates a loop that may result in some imports being undefined at runtime. The code does not produce a build error, but components fail to render.
- Import path does not match the actual file location — typo or wrong directory
- Default import used but the file has a named export, or vice versa
- File name casing in the import does not match the actual file name on disk
- Circular dependency chain where files import each other in a loop
- The @/ path alias is not configured or points to the wrong directory
Error messages you might see
Failed to resolve import "@/components/UserProfile" from "src/pages/Dashboard.tsx". Does the file exist?Vite cannot find the file at the specified path. Check: does src/components/UserProfile.tsx exist? Is the filename spelled correctly with exact casing? Is the export a default or named export?
'UserProfile' is not exported from '@/components/UserProfile'The file exists but does not export a component with that name. Check whether the export is default (export default UserProfile) or named (export const UserProfile). Match your import style to the export.
Cannot find module '../../components/Sidebar' or its corresponding type declarationsRelative path imports are fragile and break when files move. Switch to the @/ path alias: import Sidebar from '@/components/Sidebar'.
failed to resolve import "react-router-dom" from "src/main.jsx". Does the file exist?The react-router-dom package is not installed. Ask Lovable to install it by prompting: 'Install the react-router-dom npm package.'
Before you start
- A Lovable project with import errors in the console or build output
- Access to Dev Mode or the Lovable chat to see error messages
- The file tree visible in Dev Mode to verify file locations
How to fix it
Use the @/ path alias for all imports
The @/ alias always resolves from src/, making imports reliable regardless of the importing file's location
Use the @/ path alias for all imports
The @/ alias always resolves from src/, making imports reliable regardless of the importing file's location
Replace all relative imports (starting with ./ or ../) with the @/ path alias. In Lovable projects, @/ maps to the src/ directory. So @/components/UserProfile resolves to src/components/UserProfile.tsx. This approach is more maintainable because the import path stays the same even if you move the importing file to a different directory.
// Fragile relative imports:import Sidebar from "../../components/Sidebar";import { useAuth } from "../hooks/useAuth";import Dashboard from "./pages/Dashboard";// Reliable @/ imports:import Sidebar from "@/components/Sidebar";import { useAuth } from "@/hooks/useAuth";import Dashboard from "@/pages/Dashboard";Expected result: All imports resolve correctly using the @/ alias. Moving files no longer breaks import paths.
Match import syntax to export syntax
Default and named exports require different import syntax — using the wrong one causes the import to fail
Match import syntax to export syntax
Default and named exports require different import syntax — using the wrong one causes the import to fail
Check whether the file you are importing uses a default export or a named export. Default exports use export default ComponentName and are imported without curly braces: import ComponentName from '@/components/ComponentName'. Named exports use export const ComponentName and must be imported with curly braces: import { ComponentName } from '@/components/ComponentName'.
// File: src/components/UserProfile.tsxexport const UserProfile = () => { ... };// Wrong: trying to use default import syntaximport UserProfile from "@/components/UserProfile";// Named export → named import (with curly braces)import { UserProfile } from "@/components/UserProfile";// OR: change the export to defaultexport default UserProfile;// Then: import UserProfile from "@/components/UserProfile";Expected result: The import syntax matches the export syntax. No more 'is not exported from' errors.
Fix circular dependencies
Circular imports create a loop where some modules are undefined when first referenced
Fix circular dependencies
Circular imports create a loop where some modules are undefined when first referenced
Circular dependencies happen when file A imports from file B, and file B imports from file A (directly or through a chain). This causes one of the imports to be undefined at runtime. Fix by extracting the shared code into a third file that both A and B import from. Common candidates for extraction: shared types, utility functions, and constants.
// Circular dependency:// UserProfile imports from useAuth// useAuth imports from UserProfile// Result: one of them is undefined at runtime// Fix: extract shared types to a third file// src/types/User.ts (new file with shared types)export type User = { id: string; name: string; };// src/hooks/useAuth.tsimport { User } from "@/types/User"; // No longer imports from UserProfile// src/components/UserProfile.tsximport { User } from "@/types/User"; // No longer imports from useAuthExpected result: The circular dependency is broken. Both files import shared code from a third file.
Verify file name casing matches import casing
Case sensitivity differences between development (macOS) and production (Linux) cause imports to fail after deployment
Verify file name casing matches import casing
Case sensitivity differences between development (macOS) and production (Linux) cause imports to fail after deployment
Open Dev Mode and check the actual file name casing in the file tree. Compare it with the casing in your import statement. They must match exactly. On macOS, import '@/components/userprofile' works even if the file is UserProfile.tsx. But on Linux (where your app is built for production), this fails. Always use PascalCase for component files and match it exactly in imports. If tracing circular dependencies and casing issues across many files is complex, RapidDev's engineers have resolved import issues across 600+ Lovable projects.
// File on disk: src/components/UserProfile.tsx// Import: wrong casingimport UserProfile from "@/components/userprofile";// Works on macOS, FAILS on Linux/production// File on disk: src/components/UserProfile.tsx// Import: exact casing matchimport UserProfile from "@/components/UserProfile";// Works everywhereExpected result: Import casing matches the file name exactly. The import works on all platforms including production servers.
Complete code example
1// All imports use @/ alias with exact casing2import { useAuth } from "@/hooks/useAuth";3import { Sidebar } from "@/components/layout/Sidebar";4import { StatsCard } from "@/components/dashboard/StatsCard";5import { OrdersTable } from "@/components/dashboard/OrdersTable";6import { Button } from "@/components/ui/button";78// Type imported from a shared types file (no circular dependency)9import type { Order } from "@/types/Order";1011const Dashboard = () => {12 const { user } = useAuth();1314 return (15 <div className="flex min-h-screen">16 <Sidebar />17 <main className="flex-1 p-6 space-y-6">18 <h1 className="text-2xl font-bold">19 Welcome, {user?.name ?? "User"}20 </h1>21 <div className="grid grid-cols-1 md:grid-cols-3 gap-6">22 <StatsCard title="Total Orders" value="1,234" />23 <StatsCard title="Revenue" value="$12,345" />24 <StatsCard title="Customers" value="567" />25 </div>26 <OrdersTable />27 </main>28 </div>29 );30};3132export default Dashboard;Best practices to prevent this
- Always use the @/ path alias instead of relative imports (../../) — it resolves from src/ consistently
- Match import syntax to export syntax: default exports without braces, named exports with braces
- Use PascalCase for component file names and match the casing exactly in import paths
- Extract shared types and utilities into separate files to avoid circular dependencies
- If an import fails, check Dev Mode file tree to verify the file exists at the expected path
- Add the .tsx extension explicitly in imports if auto-resolution fails (rarely needed in Vite)
- When renaming files, update all imports across the project in the same prompt
- Run a build check (ask Lovable to verify the project builds) to catch import errors early
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
My Lovable project has import errors. Here are the error messages: [paste the error messages] And here is my current file structure: [paste file tree or list of component files] Please: 1. Identify the cause of each import error 2. Fix all import paths to use the @/ alias 3. Check for circular dependencies and suggest how to break them 4. Verify that import syntax matches export syntax for each file 5. Flag any case sensitivity mismatches
Fix all import errors in my project. Convert all relative imports (../../) to use the @/ path alias. Check that every import matches the export type: use curly braces for named exports and no braces for default exports. Verify that file name casing in imports matches the actual file names. If there are circular dependencies, extract shared types to @src/types/ files. Do not change any component functionality — only fix imports.
Frequently asked questions
What is the @/ path alias in Lovable?
The @/ alias maps to your src/ directory. So @/components/Button resolves to src/components/Button.tsx. It is configured in both tsconfig.json and vite.config.ts. Always use it instead of relative paths.
Why does my import work in preview but fail after deployment?
Most likely a case sensitivity issue. macOS file systems are case-insensitive, so wrong casing works locally. Linux servers are case-sensitive, so the import fails. Check that the casing in your import exactly matches the file name.
How do I know if I have a circular dependency?
Signs include: a component renders as undefined despite being exported correctly, or you get 'Cannot access X before initialization' errors. Trace the import chain: if file A imports B and B imports A (directly or through other files), you have a circular dependency.
Should I use default exports or named exports?
Either works, but be consistent. Lovable's AI typically uses default exports for page and component files. Named exports are useful when a file exports multiple items. Add your preference to AGENTS.md.
How do I fix 'Does the file exist?' errors?
Open Dev Mode and check the file tree. Verify: (1) the file exists at the path in the import, (2) the spelling and casing match exactly, (3) the file has the correct export statement. If the file does not exist, the AI may have failed to create it.
What if I can't fix this myself?
If your project has many broken imports across dozens of files with circular dependencies, RapidDev's engineers can audit and fix the entire import structure. They have resolved import issues across 600+ Lovable projects.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation