Core functionality for creating Next.js projects from templates or examples with comprehensive configuration support and error handling.
Main function that orchestrates the entire project creation process including validation, template installation, example downloading, and project setup.
/**
* Create a new Next.js application with specified configuration
* @param options - Configuration options for the new project
* @throws DownloadError - When example download fails
*/
async function createApp(options: CreateAppOptions): Promise<void>;
interface CreateAppOptions {
/** Target directory path for the new application */
appPath: string;
/** Package manager to use for dependency installation */
packageManager: PackageManager;
/** Example name from Next.js examples or GitHub URL */
example?: string;
/** Path within example repository for complex URLs */
examplePath?: string;
/** Enable TypeScript configuration */
typescript: boolean;
/** Enable Tailwind CSS configuration */
tailwind: boolean;
/** Enable ESLint configuration */
eslint: boolean;
/** Enable Biome configuration */
biome: boolean;
/** Use App Router instead of Pages Router */
app: boolean;
/** Organize code inside src/ directory */
srcDir: boolean;
/** Custom import alias pattern */
importAlias: string;
/** Skip package installation step */
skipInstall: boolean;
/** Create minimal empty project */
empty: boolean;
/** Create API-only project */
api?: boolean;
/** Enable Turbopack for development */
turbopack: boolean;
/** Use Rspack as bundler */
rspack: boolean;
/** Skip git repository initialization */
disableGit?: boolean;
}Usage Examples:
The createApp function is the core internal function that orchestrates the entire project creation process. It is called by the CLI after processing user inputs and prompts.
The creation process includes comprehensive validation steps before project setup.
Validation Steps:
The function supports two main creation modes:
Template Mode (Default):
Example Mode:
/**
* Custom error class for download failures
*/
class DownloadError extends Error {
constructor(message: string);
}Error Scenarios:
Error Handling Examples:
The CLI automatically handles DownloadError exceptions by offering users the option to fall back to the default template when example downloads fail.
After successful project creation, the function performs additional setup:
Git Initialization:
Success Output:
Example Output:
Success! Created my-next-app at /path/to/my-next-app
Inside that directory, you can run several commands:
npm run dev
Starts the development server.
npm run build
Builds the app for production.
npm start
Runs the built app in production mode.
We suggest that you begin by typing:
cd my-next-app
npm run devThe function processes configuration options to determine the appropriate template and settings:
Template Selection Logic:
const template: TemplateType = `${app ? 'app' : 'default'}${tailwind ? '-tw' : ''}${empty ? '-empty' : ''}`;Mode Selection:
const mode: TemplateMode = typescript ? 'ts' : 'js';Special Cases: