{"id":"68e453d8bbdb7c61","repo":"vitejs/vite","slug":"the-build-was-canceled","errorCode":null,"errorMessage":"The build was canceled","messagePattern":"The build was canceled","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/vite/src/node/optimizer/index.ts","lineNumber":865,"sourceCode":"      transform: {\n        target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,\n        ...rolldownOptions.transform,\n        define,\n      },\n      resolve: {\n        extensions: ['.tsx', '.ts', '.jsx', '.js', '.css', '.json'],\n        ...rolldownOptions.resolve,\n      },\n      // TODO: remove this and enable rolldown's CSS support later\n      moduleTypes: {\n        '.css': 'js',\n        ...rolldownOptions.moduleTypes,\n        ...(jsxLoader ? { '.js': 'jsx' } : {}),\n      },\n    })\n    if (canceled) {\n      await bundle.close()\n      throw new Error('The build was canceled')\n    }\n    try {\n      return await bundle.write({\n        ...rolldownOptions.output,\n        format: 'esm',\n        sourcemap: 'hidden',\n        dir: processingCacheDir,\n        entryFileNames: '[name].js',\n      })\n    } finally {\n      await bundle.close()\n    }\n  }\n\n  function cancel() {\n    canceled = true\n  }\n","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/optimizer/index.ts#L847-L883","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","solutions":["Retry the dev-server start — a one-off cancellation during cold start usually self-heals on the next optimize.","Avoid killing the server in the brief window of initial optimization; let it finish or use `--force` to re-run cleanly.","Clear `node_modules/.vite` if errors persist (corrupted cache can cause repeated cancellations).","If you drive the optimizer programmatically, don't cancel a run you intend to keep; coordinate cancel/commit."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Wrap server start so a cancelled cold optimize doesn't crash the process:\ntry { await server.listen() }\ncatch (e) {\n  if (e instanceof Error && /build was canceled/i.test(e.message)) {\n    await server.close(); /* retry once */ return createServer(config)\n  }\n  throw e\n}","preventionTips":["Let the initial optimize finish before stopping the server.","Use --force to reset optimizer state instead of killing mid-run.","Clear node_modules/.vite when cold-start errors repeat."],"tags":["optimizer","internal","race-condition","cancellation"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}