vitejs/vite · warning · Error

The build was canceled

Error message

The build was canceled

What it means

Inside the deps optimization `build()`, right after creating the rolldown bundle, Vite re-checks the `canceled` flag and, if it was flipped during bundle creation, closes the bundle and throws at optimizer/index.ts:865. This prevents writing a stale/aborted optimization to the cache when a newer run or server shutdown superseded it.

Source

Thrown at packages/vite/src/node/optimizer/index.ts:865

      transform: {
        target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
        ...rolldownOptions.transform,
        define,
      },
      resolve: {
        extensions: ['.tsx', '.ts', '.jsx', '.js', '.css', '.json'],
        ...rolldownOptions.resolve,
      },
      // TODO: remove this and enable rolldown's CSS support later
      moduleTypes: {
        '.css': 'js',
        ...rolldownOptions.moduleTypes,
        ...(jsxLoader ? { '.js': 'jsx' } : {}),
      },
    })
    if (canceled) {
      await bundle.close()
      throw new Error('The build was canceled')
    }
    try {
      return await bundle.write({
        ...rolldownOptions.output,
        format: 'esm',
        sourcemap: 'hidden',
        dir: processingCacheDir,
        entryFileNames: '[name].js',
      })
    } finally {
      await bundle.close()
    }
  }

  function cancel() {
    canceled = true
  }

View on GitHub (pinned to 89620f09af)

Solutions

  1. Retry the dev-server start — a one-off cancellation during cold start usually self-heals on the next optimize.
  2. Avoid killing the server in the brief window of initial optimization; let it finish or use `--force` to re-run cleanly.
  3. Clear `node_modules/.vite` if errors persist (corrupted cache can cause repeated cancellations).
  4. If you drive the optimizer programmatically, don't cancel a run you intend to keep; coordinate cancel/commit.
Defensive patterns

Strategy: try-catch

Try / catch

// Wrap server start so a cancelled cold optimize doesn't crash the process:
try { await server.listen() }
catch (e) {
  if (e instanceof Error && /build was canceled/i.test(e.message)) {
    await server.close(); /* retry once */ return createServer(config)
  }
  throw e
}

Prevention

When it happens

Trigger: The optimization run's `cancel()` is called while the rolldown bundle is being created (between `rolldown(...)` and `bundle.write(...)`). On the next line the canceled check fires.

Common situations: Server stopped during the first optimize; a file change triggered re-discovery that cancelled the in-flight run; HMR/discovery racing the initial cold optimize; custom code calling the internal `cancel`.

Related errors


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/68e453d8bbdb7c61.json. Report an issue: GitHub.