Lovable to Next.js: Complete Export and Migration Guide (2026)
1. Before You Start: Should You Actually Migrate to Next.js?
What it looks like: You want SSR, better SEO, or a framework you can hand to a traditional dev team. Lovable doesn't export Next.js natively, so you're planning to export the code and migrate it yourself.
The 2026 wrinkle: Projects created in Lovable after April 2026 ship on TanStack Start -- a full-stack React framework with server-side rendering built in, not Vite SPA. If your project is post-April 2026, open your package.json and check for @tanstack/react-start. If it's there, you already have SSR. Migrating to Next.js from TanStack Start is a framework swap, not a quick fix.
Migrate to Next.js if:
- Your project is pre-April 2026 (Vite + React) and you need SSR or SSG
- Your team has an existing Next.js monorepo and consolidation makes sense
- You need Next.js-specific features: ISR, server actions, or App Router middleware
- You're replacing Lovable-managed Supabase with a self-hosted instance and need server-side auth
Don't migrate if:
- You're post-April 2026 on TanStack Start -- you already have SSR
- Your SEO issue is thin content or missing meta tags, not rendering -- that's fixable without a framework swap
- The migration timeline exceeds your launch deadline by more than a week
2. What Lovable Actually Gives You When You Export
What it looks like: You click "Export to GitHub" in Lovable and get a repository. The stack depends on when the project was created.
Pre-April 2026 projects (most existing projects): React + Vite + TypeScript + Supabase. Client-side routing via react-router-dom. No SSR. All Supabase calls are in the client -- the supabaseClient is instantiated with createClient() using VITE_SUPABASE_URL and VITE_SUPABASE_ANON_KEY env vars.
Post-April 2026 projects: TanStack Start + Vite + TypeScript + Supabase. Server-side rendering already active. If you export one of these and try to migrate to Next.js App Router, you're doing a full framework swap between two SSR systems.
What you will find in the export either way:
- Supabase calls scattered across components -- not centralized in one service layer
- Auth state managed via Supabase client-side listeners
- CSS using Tailwind with a
tailwind.config.tsthat references specific content paths - Shadcn/UI components in
src/components/ui/ - Dependency versions that were current at generation time -- which may not be the latest
3. The 5 Things That Break in Every Lovable to Next.js Migration
3a. Supabase Auth Breaks First
What it looks like: Users can't log in after migration, or they get logged in but the session doesn't persist across page loads. In the console: AuthSessionMissingError or silent redirect loops.
Why it happens: Lovable generates Supabase auth using @supabase/supabase-js with a browser client. Next.js requires @supabase/ssr for server-side session handling. The two packages handle cookies differently -- the browser client can't read the httpOnly cookies that Next.js server components expect.
How to fix it:
- Replace
@supabase/supabase-jsbrowser client with@supabase/ssr:npm install @supabase/ssr. Do not run both packages simultaneously -- they conflict. - Create two separate client utilities: one for Server Components (
createServerClient) and one for Client Components (createBrowserClient). - Add middleware to
middleware.tsthat refreshes the session on every request. - Update Supabase dashboard: Authentication > URL Configuration: add your new Next.js domain to Site URL and Redirect URLs.
When to call an expert: If you're seeing different auth behavior between local and production after fixing the above, the issue is usually Vercel's edge runtime stripping cookies. That's a 30-minute fix in isolation but hard to diagnose without seeing the full middleware chain.
3b. Environment Variables Break on CI
What it looks like: The app runs locally but the Vercel/Netlify build fails with process.env.VITE_SUPABASE_URL is undefined or auth silently fails in production.
Why it happens: Lovable uses VITE_* prefix for env vars (Vite convention). Next.js requires NEXT_PUBLIC_* for client-accessible vars. In 2026, Supabase also deprecated the legacy anon key format in favour of sb_publishable_xxx keys -- if your Lovable project pre-dates this, the key format itself may be changing under you.
How to fix it:
- In your Next.js project, rename all
VITE_SUPABASE_URLtoNEXT_PUBLIC_SUPABASE_URLandVITE_SUPABASE_ANON_KEYtoNEXT_PUBLIC_SUPABASE_ANON_KEY. - Do a global search for any other
VITE_prefixed variables in the codebase and rename them. - Add all renamed variables to Vercel's environment variables dashboard before deploying.
- If you're using Supabase's new publishable key format, update the key value too -- not just the variable name.
3c. File-Based Routing vs. React Router
What it looks like: All your routes are defined in a single App.tsx with <Routes> and <Route> components. Next.js App Router expects a app/ directory with page.tsx files.
How to fix it:
- Map each
<Route path="/x">to anapp/x/page.tsxfile. Removereact-router-domfrom dependencies after the migration. - Replace all
useNavigate()calls with Next.jsrouter.push()fromuseRouter(). - Replace all
<Link to="/">with Next.js<Link href="/">. - Move any layout wrapping (nav, footer) to
app/layout.tsx.
3d. Case-Sensitive Import Paths Fail on Vercel
What it looks like: The build works locally on macOS but fails on Vercel's Linux build server with Module not found: Can't resolve './Components/Button'.
Why it happens: macOS file system is case-insensitive by default. Linux is not. Lovable sometimes generates imports like import Button from './Components/Button' while the file is actually at ./components/button.tsx.
How to fix it: Run a recursive search on your src/ directory for import paths and fix any where the capitalisation doesn't match the actual filename. Enable TypeScript's forceConsistentCasingInFileNames: true in tsconfig.json to catch this class of error at compile time.
3e. Supabase RLS Is Still Off
What it looks like: After migration, authenticated users can read and write each other's data. No error -- it just silently works when it shouldn't.
Why it happens: 89% of Lovable apps we've audited have Row Level Security disabled on their Supabase tables. The migration to Next.js doesn't enable it -- you have to do it explicitly in Supabase dashboard before going live.
How to fix it: In Supabase dashboard > Table Editor > each table > RLS > Enable. Then add at minimum: USING (auth.uid() = user_id) for user-owned rows.
Stuck on the auth migration specifically?
Auth is the part of the Lovable to Next.js migration that most commonly derails timelines. If you've worked through the steps above and sessions still aren't persisting, a 30-min discovery call usually isolates the root cause in under an hour. Free, no commitment.
4. Step-by-Step Migration
This sequence minimises back-tracking. Don't skip to step 4 before step 2 is working.
- Export and bootstrap: Export from Lovable to GitHub. Create a new Next.js 14+ project with App Router:
npx create-next-app@latest my-app --typescript --app. Don't start copying files yet. - Get it running locally first: Clone your Lovable export. Run
npm install && npm run dev. Fix any dependency errors before migrating anything. - Copy UI components: Move
src/components/ui/(Shadcn) into the Next.js project first -- these are framework-agnostic and usually move cleanly. - Migrate routing: Convert each React Router route to an
app/page file. Don't connect to Supabase yet. - Fix the auth layer: Install
@supabase/ssr, wire up the server client, browser client, and middleware. Test login before anything else. - Migrate Supabase data calls: Move
supabase.from('table').select()calls into Server Components where they can run server-side, keeping only truly interactive calls in Client Components. - Fix imports, env vars, and TypeScript: Run
npx tsc --noEmit. Fix every error -- don't ignore them. Deploy to Vercel preview (not production) and verify the build passes. - Enable RLS: Before pointing your domain at the production build, enable Row Level Security on all tables.
5. When Self-Migration Stops Making Sense
Most of the issues above are solvable with the steps provided. Some situations signal that continued self-migration has diminishing returns:
- Your Supabase schema is complex -- multiple tables with inter-table RLS policies, custom auth claims, or database functions that reference specific auth.uid() patterns don't migrate cleanly with find-and-replace
- You're on a launch timeline -- every week the migration extends is a week your app isn't generating revenue or attracting investors
- You need SSO, custom JWT claims, or webhook-driven auth -- these require server-side patterns that are significantly different from Lovable's client-only approach
- Your team doesn't have Next.js experience -- App Router is genuinely different from Pages Router and from Vite SPA; the learning curve is real
6. Migration Path Comparison
| Approach | Time | What you own | Biggest risk |
|---|---|---|---|
| Manual migration (this guide) | 3-7 days | Everything | Auth migration stalls |
| AI-assisted (Cursor/Claude Code) | 1-3 days | Everything | Context window fills at step 5-6; AI rewrites break working code |
| Migration tool (IndieKit, ViteToNext.AI) | Hours | Everything | Supabase auth not handled; RLS still off; you get code, not a working app |
| AppStuck migration | 2-4 weeks | Everything | None -- fixed-price, production-ready delivery |
Related Guides
- Lovable app won't deploy to production -- fix guide 2026
- Lovable troubleshooting guide: 10 most common errors
- Lovable app rescue and completion -- when you need more than a migration guide
Still stuck after trying these fixes?
AppStuck specialises in Lovable migrations and completions. We've migrated every type of Lovable project to Next.js -- from simple landing pages to complex multi-tenant SaaS apps -- across 300+ production codebases. We'll tell you honestly whether the migration is worth doing and what it costs before any work starts.
Book a free 30-minute assessmentFAQs
Can I export Lovable code to Next.js directly?
No. Lovable exports a React + Vite app (or TanStack Start if post-April 2026). There's no one-click Next.js export. You have to export the code, create a new Next.js project, and migrate the components, routing, and Supabase auth manually or with an AI assistant.
Do I need Next.js if I already have a Lovable app in 2026?
Not necessarily. Projects created after April 2026 in Lovable run on TanStack Start, which has server-side rendering built in. Check your package.json for @tanstack/react-start -- if it's there, you already have SSR and most Next.js migration motivations don't apply.
What happens to my Supabase data when I migrate?
Your Supabase database stays exactly where it is -- the migration only changes the frontend framework. The Supabase project URL, anon key, and all your tables are untouched. You're just changing how your app connects to them.
Will my Lovable Supabase auth work in Next.js without changes?
No. Lovable uses the standard @supabase/supabase-js browser client, which doesn't handle server-side sessions. Next.js needs @supabase/ssr to persist authentication across server and client components. This is the most common migration blocker we see.
How long does a Lovable to Next.js migration take?
For a typical Lovable app (5-10 routes, Supabase auth, standard Shadcn UI), a solo developer with Next.js experience takes 3-5 days. Without Next.js experience, plan for 2-3 weeks. Most of that time is auth, not routing or components.
What is the biggest mistake developers make migrating Lovable to Next.js?
Starting the routing migration before fixing auth. It's tempting to copy components and pages first because it feels like progress, but if auth is broken, you can't properly test anything else. Fix auth in isolation first -- local only -- before touching routing.
Can I use Cursor or Claude Code to automate the migration?
Yes, and it works well for steps 1-4 (routing, component copying, env var renaming). It struggles with the auth migration because the @supabase/ssr pattern is specific and the context window often runs out before the full middleware chain is correct. Use AI for the mechanical work, handle auth manually with this guide.
Need Help with Your AI Project?
If you're dealing with a stuck AI-generated project, we're here to help. Get your free consultation today.
Get Free Consultation