Nuxt CLI
Nuxi is the official Command Line Interface (CLI) for the Nuxt.js framework, providing essential tools for project initialization, development, building, and management. As of its current stable version 3.34.0, Nuxi maintains a rapid release cadence with frequent minor and patch updates, indicating active development and continuous improvement. It differentiates itself by offering a tightly integrated experience for Nuxt developers, including features like interactive project creation with module selection, shell completions, and simplified command structures for common tasks. Nuxi abstracts away much of the underlying build tool complexity, allowing developers to focus on application logic within the Nuxt ecosystem. It requires Node.js version 16.10.0 or higher, or 18.0.0 or higher.
Common errors
-
nuxi: command not found
cause The `nuxi` executable is not found in your system's PATH. This usually means it's not installed globally, or `npx` cannot locate the local installation.fixEnsure `nuxi` is installed as a dev dependency in your project (`npm install nuxi --save-dev`) and then use `npx nuxi <command>` or run it via a `package.json` script (e.g., `npm run dev`). -
Error: Nuxt CLI requires Node.js version ^16.10.0 || >=18.0.0. You are using Node.js v14.x.x
cause Your current Node.js version is older than the minimum required by Nuxi.fixUpgrade your Node.js version to 16.10.0 or higher, or 18.0.0 or higher. Tools like NVM (Node Version Manager) can help: `nvm install 18 && nvm use 18`. -
Failed to proxy request from 'http://localhost:3000/api/data' to 'http://localhost:5000/data' because the built-in proxy server was removed.
cause Your Nuxt project is configured to use the deprecated built-in proxy server, which was removed in Nuxi v3.30.0, leading to failed API requests.fixRemove any direct `proxy` configurations from your Nuxt CLI settings or `nuxt.config.ts` that relied on the internal proxy. Implement an external proxy solution (e.g., `@nuxtjs/proxy`, a custom server middleware, or a reverse proxy server).
Warnings
- breaking Nuxi v3.30.0 removed its built-in proxy server. Projects relying on this internal proxy for API forwarding or similar functionalities during development will now experience failures. Users must implement an alternative proxy solution.
- deprecated The `nuxi module add` command has been superseded by `nuxi add` in v3.32.0. While the older command might still be recognized for compatibility, it's recommended to update your workflows to use the new, more generalized `nuxi add` command.
- breaking Nuxi has strict Node.js engine requirements: `^16.10.0` or `>=18.0.0`. Running Nuxi with unsupported Node.js versions will lead to immediate errors and prevent project operations.
- gotcha In certain development scenarios, particularly in older versions, Nuxi's development server might override the `NODE_ENV` environment variable. This can lead to unexpected behavior if your application logic depends on a specific `NODE_ENV` value during development.
- gotcha Early versions of `nuxi init` and `nuxi module add` (before v3.31.3/v3.32.0) had issues with module compatibility filtering and verbose dependency installation logs. This could lead to selecting incompatible modules or a cluttered terminal output.
Install
-
npm install nuxi -
yarn add nuxi -
pnpm add nuxi
Imports
- nuxi (CLI via npx)
npm install -g nuxi && nuxi <command>
npx nuxi <command>
- nuxi (package.json script)
"scripts": { "dev": "nuxt dev" }"scripts": { "dev": "nuxi dev", "build": "nuxi build", "preview": "nuxi preview" } - runMain (programmatic)
import nuxi from 'nuxi'; // No default export for a direct programmatic API
import { runMain } from 'nuxi/dist/shared/nuxi'; async function executeNuxiCommand() { // Example: Programmatically run 'nuxi build ./path/to/my-project' await runMain(['build', './path/to/my-project']); console.log('Nuxt build completed programmatically.'); } executeNuxiCommand();
Quickstart
# Initialize a new Nuxt 3 project in a directory named 'my-nuxt-project'. # This command will interactively guide you through setting up project preferences # such as package manager, TypeScript support, and common Nuxt modules. npx nuxi init my-nuxt-project # Navigate into your newly created project directory to continue setup. cd my-nuxt-project # Install the necessary project dependencies using your chosen package manager (e.g., npm, yarn, pnpm). # This step fetches all required packages, including Nuxt itself and any modules you selected during initialization. npm install # Start the Nuxt development server. This command compiles your application # and provides hot module reloading, making it easy to see changes instantly. # Your application will typically be accessible in your web browser at http://localhost:3000. npm run dev # After development, you can build your application for production using: # npm run build