Complete Guide to Setting Up NX + Next.js + Expo Project: Modern Monorepo Architecture. Part 1
By Aleksandr
Published on July 2025
Complete Guide to Setting Up NX + Next.js + Expo: Modern Cross-Platform Monorepo
Building modern applications often requires managing multiple platforms simultaneously: web applications, mobile apps, and backend APIs. NX provides the perfect foundation for this challenge by offering a monorepo architecture that enables code sharing, consistent tooling, and optimized build processes across web, mobile, and server applications. This comprehensive guide will walk you through creating a production-ready NX workspace that combines Next.js for web development and Expo for cross-platform mobile apps.
What You’ll Master
NX workspace creation with cross-platform architecture
Next.js application setup with App Router and Tailwind CSS
NestJS API configuration for backend services
Expo mobile app integration with React Native 0.79+
Optimal project structure for web and mobile code sharing
Development workflow optimization and package management
Why Choose NX for Cross-Platform Development?
The combination of NX with Next.js and Expo addresses the fundamental challenge of modern app development: building for multiple platforms without duplicating business logic, UI components, or development processes. NX provides intelligent dependency management, affected change detection, and build optimization, while Next.js delivers server-side rendering and modern React features for web, and Expo enables native mobile development with React Native.
Top tip
NX version 21+ introduces enhanced cross-platform support with improved task inference and better dependency graph visualization. This reduces configuration overhead while maintaining complete control over your build pipeline.
Prerequisites and Installation
Before creating your cross-platform NX workspace, ensure you have the following tools installed:
# Check Node.js version (18+ recommended)node --version# Check npm versionnpm --version# Install NX CLI globally for workspace managementnpm i -g nx
For mobile development, you’ll also need:
iOS Development: Xcode (macOS only)
Android Development: Android Studio and Android SDK
Expo CLI: Will be installed automatically with the Expo plugin
Creating Your Cross-Platform NX Workspace
Step 1: Initialize Empty NX Workspace
Start with an empty workspace to have complete control over the architecture and gradually add applications as needed:
# Create empty workspace with maximum flexibilitynpx create-nx-workspace@latest
Follow the interactive prompts:
Where would you like to create your workspace? → monorepo-heaven
Which stack do you want to use? → none
Would you like to use Prettier for code formatting? → Yes
Which CI provider would you like to use? → skip
Would you like remote caching to make your build faster? → skip
Step 2: Clean Up Package Configuration
After workspace creation, remove the default workspaces configuration that may conflict with NX’s dependency management:
Now you can run your applications with simple commands:
# Start web development serveryarn web:dev# Start API development serveryarn api:dev# Start mobile development with Expoyarn mobile:dev# Build all applicationsyarn build:all# View dependency graphyarn graph
Understanding Your Workspace Structure
Your completed NX workspace now has a clean, scalable architecture:
monorepo-heaven/├── apps/│ ├── web/ # Next.js web application│ ├── api/ # NestJS backend API│ └── mobile/ # Expo mobile application├── libs/ # Shared libraries (empty for now)├── tools/ # Custom scripts and configurations├── nx.json # NX workspace configuration├── package.json # Root package management└── tsconfig.base.json # Base TypeScript configuration
Development Commands Reference
Application-Specific Commands
# Web application commandsnx dev web # Start development servernx build web # Build for productionnx lint web # Lint web application# API application commandsnx serve api # Start API development servernx build api # Build API for productionnx lint api # Lint API code# Mobile application commandsnx serve mobile # Start Expo development servernx build mobile # Build mobile applicationnx lint mobile # Lint mobile code
Workspace-Wide Commands
# Multi-project operationsnx run-many --target=build --all # Build all applicationsnx run-many --target=lint --all # Lint all projectsnx affected:build # Build only affected projectsnx affected:test # Test only affected projects# Workspace managementnx graph # View dependency graphnx reset # Clear NX cachenx report # Generate workspace report
Next Steps and Architecture Planning
With your foundational NX workspace established, you’re ready to build scalable cross-platform applications. The next phase involves:
Immediate Development Tasks
Create shared component libraries for code reuse between web and mobile
Implement API endpoints in your NestJS application
Set up state management and data fetching patterns
Configure shared TypeScript types across all applications
Advanced Architecture Considerations
Design a shared UI component system that works across platforms
Implement authentication and authorization across web and mobile
Set up shared business logic libraries
Configure deployment pipelines for each platform
Top tip
Start simple with your shared libraries. Begin by extracting common TypeScript interfaces and utility functions before moving to complex component sharing between web and mobile platforms.
Troubleshooting Common Setup Issues
React Native Version Conflicts
If you encounter React Native version issues:
# Clear all caches and reinstallrm -rf node_modulesnpm cache clean --forcenpm install# Reset NX cachenpx nx reset
Metro Bundler Configuration
For mobile development issues, ensure your Metro config is properly set up:
You’ve successfully created a powerful foundation for cross-platform development using NX, Next.js, and Expo. This setup provides a scalable monorepo architecture that enables code sharing between web and mobile applications while maintaining the flexibility to optimize each platform independently.
The workspace you’ve built includes modern development tools, optimized build processes, and a clean project structure that will grow with your application’s complexity. With Next.js powering your web experience, NestJS handling your backend API, and Expo enabling cross-platform mobile development, you have all the essential pieces for building comprehensive modern applications.
In the next part of this series, we’ll dive deep into creating shared libraries, implementing cross-platform components, and establishing data flow patterns that maximize code reuse while maintaining platform-specific optimizations. The foundation you’ve established here will serve as the launching point for building sophisticated, maintainable applications that deliver exceptional user experiences across all platforms.