Fix: Failed to Install @nuxt/webpack-builder in Nuxt

Error message:
Failed to install `@nuxt/webpack-builder`. Please install it manually or use Vite builder.
initialization 2025-01-25

What Causes This Warning?

This warning appears when you configure Nuxt to use Webpack as the builder but the @nuxt/webpack-builder package isn’t installed or fails to install automatically.

The Problem

// nuxt.config.ts
export default defineNuxtConfig({
  builder: 'webpack'  // Requires @nuxt/webpack-builder
})

But @nuxt/webpack-builder is not in your dependencies.

The Fix

Option 1: Install Webpack Builder

# npm
npm install -D @nuxt/webpack-builder

# pnpm
pnpm add -D @nuxt/webpack-builder

# yarn
yarn add -D @nuxt/webpack-builder

Vite is the default and recommended builder for Nuxt 3:

// nuxt.config.ts
export default defineNuxtConfig({
  // Remove builder option to use Vite (default)
  // builder: 'webpack'  ← Remove this
})

Or explicitly set Vite:

// nuxt.config.ts
export default defineNuxtConfig({
  builder: 'vite'  // Explicit but optional
})

When to Use Webpack

Valid Reasons

  • Legacy dependencies that require Webpack
  • Specific Webpack plugins you need
  • Existing Webpack configuration to migrate

Better with Vite

  • New projects
  • Faster development builds
  • Modern ES modules
  • Better HMR (Hot Module Replacement)

Webpack Configuration

If you need Webpack:

// nuxt.config.ts
export default defineNuxtConfig({
  builder: 'webpack',

  webpack: {
    // Webpack-specific configuration
    extractCSS: true,

    optimization: {
      splitChunks: {
        chunks: 'all'
      }
    },

    plugins: [
      // Custom webpack plugins
    ]
  }
})

Vite Equivalent Features

Most Webpack features have Vite equivalents:

CSS Extraction

// Webpack
webpack: {
  extractCSS: true
}

// Vite (automatic in production)
vite: {
  build: {
    cssCodeSplit: true
  }
}

Aliases

// Both work the same
alias: {
  '@': '/src',
  '~': '/src'
}

Plugins

// Vite plugins
vite: {
  plugins: [
    myVitePlugin()
  ]
}

Migrating from Webpack to Vite

Check Compatibility

# List your dependencies
npm ls

# Check for webpack-specific packages
npm ls | grep webpack

Update Imports

// Webpack-style
require('./style.css')

// Vite-style (also works in Webpack)
import './style.css'

Environment Variables

// Both
process.env.MY_VAR

// Vite also supports
import.meta.env.MY_VAR

Troubleshooting Installation

Clear Cache and Retry

# Clear npm cache
npm cache clean --force

# Remove node_modules
rm -rf node_modules

# Remove lock file
rm package-lock.json  # or pnpm-lock.yaml, yarn.lock

# Reinstall
npm install
npm install -D @nuxt/webpack-builder

Check Node Version

# @nuxt/webpack-builder requires Node 18+
node --version

# If too old, upgrade Node
nvm install 18
nvm use 18

Peer Dependencies

# Install with legacy peer deps if needed
npm install -D @nuxt/webpack-builder --legacy-peer-deps

Version Compatibility

{
  "devDependencies": {
    "nuxt": "^3.0.0",
    "@nuxt/webpack-builder": "^3.0.0"  // Match Nuxt version
  }
}

Checking Current Builder

// nuxt.config.ts
export default defineNuxtConfig({
  hooks: {
    ready(nuxt) {
      console.log('Builder:', nuxt.options.builder)
    }
  }
})

Quick Comparison

FeatureViteWebpack
Dev server startFastSlower
HMRInstantSlower
Build sizeSmallerLarger
Legacy supportLimitedBetter
EcosystemGrowingMature

Quick Checklist

  • Decide if you really need Webpack
  • If yes: npm install -D @nuxt/webpack-builder
  • If no: Remove builder: 'webpack' from config
  • Check Node.js version is 18+
  • Clear cache if installation fails
  • Match @nuxt/webpack-builder version with Nuxt version