Next.js 15.5+ + Firebase Development Guide
This skill provides comprehensive guidance for building modern Next.js 15.5+ applications with Firebase, TypeScript, Material-UI v7, and Node.js.
When to Use This Skill
Use this skill when:
- Setting up a new Next.js 15.5+ project with Firebase
- Configuring Next.js with TypeScript, MUI v7, or Turbopack
- Working with Next.js App Router patterns (Server Components, Client Components, routing)
- Integrating Firebase services (Auth, Firestore, Storage, Firebase SDK v12.x)
- Troubleshooting build errors, runtime errors, or deployment issues
- Implementing best practices for Next.js + Firebase projects
- Optimizing performance and build times with Turbopack (beta for production builds)
- Using Node.js Middleware (stable in 15.5)
- Working with typed routes and route props helpers
- Understanding CLI commands and configuration options
Quick Reference
Essential Commands
# Create new project (Next.js 15.5+)
npx create-next-app@latest my-app --typescript --eslint --src-dir --app
# Development
npm run dev # Start dev server (webpack by default)
npm run dev --turbopack # Start with Turbopack (faster, optional)
npm run dev -- -p 4000 # Start on custom port
# Type checking & linting
tsc --noEmit # Check types
npx eslint . # Run ESLint CLI directly (next lint deprecated in 15.5)
# Generate types for routes (NEW in 15.5)
npx next typegen # Generate route types without full build
# Build & production
npm run build # Create production build (webpack - RECOMMENDED)
npm run start # Start production server
⚠️ Important: Turbopack production builds (--turbopack flag) are in beta and NOT RECOMMENDED for production use yet. Use webpack (default) for builds.
Project Stack
- Framework: Next.js 15.5+ with App Router
- Language: TypeScript 5.9.3+
- UI Library: Material-UI (MUI) v7.3.4+
- Backend: Firebase SDK v12.x (Firestore, Auth, Storage, App Hosting)
- Bundler: webpack (default, recommended) / Turbopack (optional for dev with --turbopack flag)
- Runtime: Node.js ≥22.x (recommended)
Reference Documentation
The skill includes comprehensive reference documentation. Read these files as needed:
Core References
cli-commands.md - Complete Next.js CLI reference
- Read when: Running CLI commands, debugging dev server, configuring ports
create-next-app.md - Project initialization guide
- Read when: Creating new Next.js projects, understanding setup options
next-config.md - Configuration reference
- Read when: Configuring Next.js, setting up Firebase-specific options, troubleshooting build config
typescript.md - TypeScript integration guide
- Read when: Setting up TypeScript, using typed routes, configuring type checking
turbopack.md - Turbopack bundler reference
- Read when: Enabling Turbopack for dev (optional), understanding Turbopack limitations, troubleshooting bundler issues
Practice Guides
Key Workflows
1. Starting a New Next.js + Firebase Project
Create project:
npx create-next-app@latest my-app \
--typescript \
--eslint \
--src-dir \
--app \
--turbopack
Install Firebase and MUI:
npm install firebase # Firebase SDK v12.x
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled
Configure next.config.ts:
- Enable React Strict Mode
- Add MUI packages to transpilePackages
- Configure images for Firebase Storage
- See next-config.md for full configuration
Set up Firebase:
- Create Firebase project in console
- Add web app and get config
- Create
.env.local with Firebase credentials
- Initialize Firebase in
src/lib/firebase/config.ts
- See best-practices.md for detailed setup
Configure MUI:
- Set up ThemeProvider in root layout
- Add AppRouterCacheProvider
- Create custom theme
- See best-practices.md for MUI integration
2. Working with App Router
Server Components (default):
- Fetch data directly in components
- No 'use client' needed
- Can use async/await
- Example: best-practices.md - "App Router Patterns"
Client Components:
- Add 'use client' directive at top
- Use React hooks (useState, useEffect, etc.)
- Firebase Auth listeners
- Interactive UI elements
- Example: best-practices.md - "Client Components"
Key principle: Use Server Components by default, only add 'use client' when needed (interactivity, hooks, Firebase Auth).
3. Firebase Integration
Authentication:
- Use custom
useAuth hook for auth state
- Implement protected routes with loading states
- Handle auth errors properly
- See best-practices.md - "Firebase Authentication Patterns"
Firestore:
- Read data in Server Components when possible
- Write data in Client Components
- Use real-time listeners in Client Components
- Implement proper security rules
- See best-practices.md - "Firestore Patterns"
4. Troubleshooting Common Issues
When encountering errors, follow this process:
Identify error category:
- Build error → Check troubleshooting.md - "Build Errors"
- Runtime error → Check troubleshooting.md - "Runtime Errors"
- TypeScript error → Check troubleshooting.md - "TypeScript Errors"
- Firebase error → Check troubleshooting.md - "Firebase Errors"
Apply common solutions:
- Clear cache:
rm -rf .next node_modules && npm install
- Check environment variables
- Verify 'use client' directive placement
- Ensure proper loading state handling
Enable debug mode if needed:
NEXT_DEBUG=1 npm run dev
5. Deployment to Firebase
- Install Firebase CLI:
npm install -g firebase-tools
- Login:
firebase login
- Initialize:
firebase init hosting
- Configure firebase.json for Next.js
- Build:
npm run build
- Deploy:
firebase deploy --only hosting
See best-practices.md - "Deployment to Firebase" for detailed steps.
Important Configuration Files
next.config.ts
Essential for Firebase + MUI setup:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
reactStrictMode: true,
transpilePackages: [
'@mui/material',
'@mui/system',
'@mui/icons-material',
],
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'firebasestorage.googleapis.com',
},
],
},
}
export default nextConfig
tsconfig.json
Configure path aliases and includes:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
]
}
Best Practices Summary
Do:
- ✅ Use TypeScript for type safety
- ✅ Use Server Components by default
- ✅ Handle loading and error states
- ✅ Use environment variables for Firebase config
- ✅ Enable React Strict Mode
- ✅ Use Turbopack for faster development
- ✅ Implement Firebase Security Rules
- ✅ Optimize images with next/image
- ✅ Check if Firebase already initialized
Don't:
- ❌ Don't use Firebase Auth in Server Components
- ❌ Don't ignore TypeScript errors in production
- ❌ Don't forget loading states
- ❌ Don't initialize Firebase multiple times
- ❌ Don't create Client Components unnecessarily
- ❌ Don't expose sensitive data in client code
Progressive Reference Loading
Read reference files progressively based on task needs:
For setup tasks:
- Start with best-practices.md
- Refer to create-next-app.md for initialization
- Check next-config.md for configuration
For development tasks:
- Check best-practices.md for patterns
- Refer to typescript.md for type issues
- Check turbopack.md for bundler features
For troubleshooting:
- Start with troubleshooting.md
- Check specific error category
- Refer to relevant practice guide for correct implementation
For CLI operations:
- Check cli-commands.md for command syntax
- Refer to examples in best-practices.md
Common Task Quick Guide
| Task |
Reference |
Section |
| Create new project |
create-next-app.md |
Usage Examples |
| Set up Firebase |
best-practices.md |
Firebase Configuration |
| Configure MUI v7 |
best-practices.md |
Material-UI Integration |
| Fix hydration error |
troubleshooting.md |
Runtime Errors |
| Set up auth |
best-practices.md |
Firebase Authentication |
| Configure next.config |
next-config.md |
Firebase-Specific Config |
| Enable Turbopack |
turbopack.md |
Getting Started |
| Fix build error |
troubleshooting.md |
Build Errors |
| Deploy to Firebase |
best-practices.md |
Deployment to Firebase |
Notes
- This skill is optimized for Next.js 15.5+ with App Router (not Pages Router)
- All examples use TypeScript (not JavaScript)
- Firebase App Hosting is the deployment target (not Vercel)
- MUI v7.3.4+ is used for UI components
- webpack is the default and recommended bundler for builds
- Turbopack can be used for dev with
--turbopack flag (optional, faster HMR)
- Turbopack production builds are NOT RECOMMENDED (beta, unstable)
- Node.js Middleware is now stable (supports full Node.js APIs)
next lint command is deprecated (use ESLint CLI directly)
next typegen command is new in 15.5 (generates types without full build)
- Typed routes are now stable (enables compile-time link validation)
- Firebase SDK v12.x is the current version
Getting Help
If you encounter issues not covered in the troubleshooting guide:
- Check Next.js documentation: https://nextjs.org/docs
- Check Firebase documentation: https://firebase.google.com/docs
- Search GitHub issues for Next.js and Firebase
- Enable debug mode:
NEXT_DEBUG=1 npm run dev
1---2name: nextjs-firebase3description: Comprehensive guide for building Next.js 15.5+ applications with Firebase, including App Router, TypeScript, MUI v7, Turbopack production builds (beta), and Firebase services. Use when configuring Next.js projects, troubleshooting errors, setting up Firebase integration, working with App Router patterns, or implementing best practices for Next.js + Firebase development.4---56# Next.js 15.5+ + Firebase Development Guide78This skill provides comprehensive guidance for building modern Next.js 15.5+ applications with Firebase, TypeScript, Material-UI v7, and Node.js.910## When to Use This Skill1112Use this skill when:13- Setting up a new Next.js 15.5+ project with Firebase14- Configuring Next.js with TypeScript, MUI v7, or Turbopack15- Working with Next.js App Router patterns (Server Components, Client Components, routing)16- Integrating Firebase services (Auth, Firestore, Storage, Firebase SDK v12.x)17- Troubleshooting build errors, runtime errors, or deployment issues18- Implementing best practices for Next.js + Firebase projects19- Optimizing performance and build times with Turbopack (beta for production builds)20- Using Node.js Middleware (stable in 15.5)21- Working with typed routes and route props helpers22- Understanding CLI commands and configuration options2324## Quick Reference2526### Essential Commands2728```bash29# Create new project (Next.js 15.5+)30npx create-next-app@latest my-app --typescript --eslint --src-dir --app3132# Development33npm run dev # Start dev server (webpack by default)34npm run dev --turbopack # Start with Turbopack (faster, optional)35npm run dev -- -p 4000 # Start on custom port3637# Type checking & linting38tsc --noEmit # Check types39npx eslint . # Run ESLint CLI directly (next lint deprecated in 15.5)4041# Generate types for routes (NEW in 15.5)42npx next typegen # Generate route types without full build4344# Build & production45npm run build # Create production build (webpack - RECOMMENDED)46npm run start # Start production server47```4849**⚠️ Important:** Turbopack production builds (`--turbopack` flag) are in beta and **NOT RECOMMENDED** for production use yet. Use webpack (default) for builds.5051### Project Stack5253- **Framework:** Next.js 15.5+ with App Router54- **Language:** TypeScript 5.9.3+55- **UI Library:** Material-UI (MUI) v7.3.4+56- **Backend:** Firebase SDK v12.x (Firestore, Auth, Storage, App Hosting)57- **Bundler:** webpack (default, recommended) / Turbopack (optional for dev with --turbopack flag)58- **Runtime:** Node.js ≥22.x (recommended)5960## Reference Documentation6162The skill includes comprehensive reference documentation. Read these files as needed:6364### Core References6566- **[cli-commands.md](references/cli-commands.md)** - Complete Next.js CLI reference67 - Read when: Running CLI commands, debugging dev server, configuring ports68 69- **[create-next-app.md](references/create-next-app.md)** - Project initialization guide70 - Read when: Creating new Next.js projects, understanding setup options71 72- **[next-config.md](references/next-config.md)** - Configuration reference73 - Read when: Configuring Next.js, setting up Firebase-specific options, troubleshooting build config74 75- **[typescript.md](references/typescript.md)** - TypeScript integration guide76 - Read when: Setting up TypeScript, using typed routes, configuring type checking77 78- **[turbopack.md](references/turbopack.md)** - Turbopack bundler reference79 - Read when: Enabling Turbopack for dev (optional), understanding Turbopack limitations, troubleshooting bundler issues8081### Practice Guides8283- **[best-practices.md](references/best-practices.md)** - Comprehensive development guide84 - Read when: Starting a new project, implementing Firebase, working with App Router, setting up MUI85 - Contains: Project structure, Firebase setup, authentication patterns, Firestore patterns, routing patterns86 87- **[troubleshooting.md](references/troubleshooting.md)** - Common errors and solutions88 - Read when: Encountering build errors, runtime errors, TypeScript errors, Firebase errors, deployment issues89 - Contains: Solutions for hydration errors, module not found, Firebase auth errors, MUI setup issues9091## Key Workflows9293### 1. Starting a New Next.js + Firebase Project94951. **Create project:**96 ```bash97 npx create-next-app@latest my-app \98 --typescript \99 --eslint \100 --src-dir \101 --app \102 --turbopack103 ```1041052. **Install Firebase and MUI:**106 ```bash107 npm install firebase # Firebase SDK v12.x108 npm install @mui/material @mui/icons-material @emotion/react @emotion/styled109 ```1101113. **Configure next.config.ts:**112 - Enable React Strict Mode113 - Add MUI packages to transpilePackages114 - Configure images for Firebase Storage115 - See [next-config.md](references/next-config.md) for full configuration1161174. **Set up Firebase:**118 - Create Firebase project in console119 - Add web app and get config120 - Create `.env.local` with Firebase credentials121 - Initialize Firebase in `src/lib/firebase/config.ts`122 - See [best-practices.md](references/best-practices.md) for detailed setup1231245. **Configure MUI:**125 - Set up ThemeProvider in root layout126 - Add AppRouterCacheProvider127 - Create custom theme128 - See [best-practices.md](references/best-practices.md) for MUI integration129130### 2. Working with App Router131132**Server Components (default):**133- Fetch data directly in components134- No 'use client' needed135- Can use async/await136- Example: [best-practices.md](references/best-practices.md) - "App Router Patterns"137138**Client Components:**139- Add 'use client' directive at top140- Use React hooks (useState, useEffect, etc.)141- Firebase Auth listeners142- Interactive UI elements143- Example: [best-practices.md](references/best-practices.md) - "Client Components"144145**Key principle:** Use Server Components by default, only add 'use client' when needed (interactivity, hooks, Firebase Auth).146147### 3. Firebase Integration148149**Authentication:**150- Use custom `useAuth` hook for auth state151- Implement protected routes with loading states152- Handle auth errors properly153- See [best-practices.md](references/best-practices.md) - "Firebase Authentication Patterns"154155**Firestore:**156- Read data in Server Components when possible157- Write data in Client Components158- Use real-time listeners in Client Components159- Implement proper security rules160- See [best-practices.md](references/best-practices.md) - "Firestore Patterns"161162### 4. Troubleshooting Common Issues163164When encountering errors, follow this process:1651661. **Identify error category:**167 - Build error → Check [troubleshooting.md](references/troubleshooting.md) - "Build Errors"168 - Runtime error → Check [troubleshooting.md](references/troubleshooting.md) - "Runtime Errors"169 - TypeScript error → Check [troubleshooting.md](references/troubleshooting.md) - "TypeScript Errors"170 - Firebase error → Check [troubleshooting.md](references/troubleshooting.md) - "Firebase Errors"1711722. **Apply common solutions:**173 - Clear cache: `rm -rf .next node_modules && npm install`174 - Check environment variables175 - Verify 'use client' directive placement176 - Ensure proper loading state handling1771783. **Enable debug mode if needed:**179 ```bash180 NEXT_DEBUG=1 npm run dev181 ```182183### 5. Deployment to Firebase1841851. Install Firebase CLI: `npm install -g firebase-tools`1862. Login: `firebase login`1873. Initialize: `firebase init hosting`1884. Configure firebase.json for Next.js1895. Build: `npm run build`1906. Deploy: `firebase deploy --only hosting`191192See [best-practices.md](references/best-practices.md) - "Deployment to Firebase" for detailed steps.193194## Important Configuration Files195196### next.config.ts197Essential for Firebase + MUI setup:198```typescript199import type { NextConfig } from 'next'200201const nextConfig: NextConfig = {202 reactStrictMode: true,203 transpilePackages: [204 '@mui/material',205 '@mui/system',206 '@mui/icons-material',207 ],208 images: {209 remotePatterns: [210 {211 protocol: 'https',212 hostname: 'firebasestorage.googleapis.com',213 },214 ],215 },216}217218export default nextConfig219```220221### tsconfig.json222Configure path aliases and includes:223```json224{225 "compilerOptions": {226 "baseUrl": ".",227 "paths": {228 "@/*": ["./src/*"]229 }230 },231 "include": [232 "next-env.d.ts",233 ".next/types/**/*.ts",234 "**/*.ts",235 "**/*.tsx"236 ]237}238```239240## Best Practices Summary241242**Do:**243- ✅ Use TypeScript for type safety244- ✅ Use Server Components by default245- ✅ Handle loading and error states246- ✅ Use environment variables for Firebase config247- ✅ Enable React Strict Mode248- ✅ Use Turbopack for faster development249- ✅ Implement Firebase Security Rules250- ✅ Optimize images with next/image251- ✅ Check if Firebase already initialized252253**Don't:**254- ❌ Don't use Firebase Auth in Server Components255- ❌ Don't ignore TypeScript errors in production256- ❌ Don't forget loading states257- ❌ Don't initialize Firebase multiple times258- ❌ Don't create Client Components unnecessarily259- ❌ Don't expose sensitive data in client code260261## Progressive Reference Loading262263Read reference files progressively based on task needs:264265**For setup tasks:**2661. Start with [best-practices.md](references/best-practices.md)2672. Refer to [create-next-app.md](references/create-next-app.md) for initialization2683. Check [next-config.md](references/next-config.md) for configuration269270**For development tasks:**2711. Check [best-practices.md](references/best-practices.md) for patterns2722. Refer to [typescript.md](references/typescript.md) for type issues2733. Check [turbopack.md](references/turbopack.md) for bundler features274275**For troubleshooting:**2761. Start with [troubleshooting.md](references/troubleshooting.md)2772. Check specific error category2783. Refer to relevant practice guide for correct implementation279280**For CLI operations:**2811. Check [cli-commands.md](references/cli-commands.md) for command syntax2822. Refer to examples in [best-practices.md](references/best-practices.md)283284## Common Task Quick Guide285286| Task | Reference | Section |287|------|-----------|---------|288| Create new project | [create-next-app.md](references/create-next-app.md) | Usage Examples |289| Set up Firebase | [best-practices.md](references/best-practices.md) | Firebase Configuration |290| Configure MUI v7 | [best-practices.md](references/best-practices.md) | Material-UI Integration |291| Fix hydration error | [troubleshooting.md](references/troubleshooting.md) | Runtime Errors |292| Set up auth | [best-practices.md](references/best-practices.md) | Firebase Authentication |293| Configure next.config | [next-config.md](references/next-config.md) | Firebase-Specific Config |294| Enable Turbopack | [turbopack.md](references/turbopack.md) | Getting Started |295| Fix build error | [troubleshooting.md](references/troubleshooting.md) | Build Errors |296| Deploy to Firebase | [best-practices.md](references/best-practices.md) | Deployment to Firebase |297298## Notes299300- This skill is optimized for Next.js 15.5+ with App Router (not Pages Router)301- All examples use TypeScript (not JavaScript)302- Firebase App Hosting is the deployment target (not Vercel)303- MUI v7.3.4+ is used for UI components304- **webpack is the default and recommended bundler for builds**305- Turbopack can be used for dev with `--turbopack` flag (optional, faster HMR)306- **Turbopack production builds are NOT RECOMMENDED** (beta, unstable)307- Node.js Middleware is now stable (supports full Node.js APIs)308- `next lint` command is deprecated (use ESLint CLI directly)309- `next typegen` command is new in 15.5 (generates types without full build)310- Typed routes are now stable (enables compile-time link validation)311- Firebase SDK v12.x is the current version312313## Getting Help314315If you encounter issues not covered in the troubleshooting guide:3161. Check Next.js documentation: https://nextjs.org/docs3172. Check Firebase documentation: https://firebase.google.com/docs3183. Search GitHub issues for Next.js and Firebase3194. Enable debug mode: `NEXT_DEBUG=1 npm run dev`