Tools

Vite 8 remove console.log: why esbuild.drop is ignored and the dropConsole fix

Mayur Dabhi
Mayur Dabhi
November 20, 2026
13 min read

You bumped the project to Vite 8, npm run build is green, and the production bundle still prints console.log('user', {...}) with the whole object in DevTools. The esbuild: { drop: ['console', 'debugger'] } line in vite.config.ts hasn't moved. It just stopped doing anything. If you searched for how to make Vite 8 remove console.log calls, the top answers were written for Vite 4 to 7 and still point at that dead line.

Short answer

Vite 8 minifies with Oxc inside Rolldown, so esbuild.drop is ignored. Set build.rolldownOptions.output.minify.compress to { dropConsole: true, dropDebugger: true } instead. Use camelCase: snake_case drop_console only prints an "Invalid output options" warning. dropConsole removes every console method, console.error included. To keep error and warn, use compress.treeshake.manualPureFunctions: ['console.log', 'console.debug', 'console.info'] instead.

Why does Vite 8 ignore esbuild.drop?

Vite 8 ignores esbuild.drop because esbuild no longer minifies your code, and the step that converts old esbuild options to Oxc options skips drop without telling you. Vite 8 shipped on March 12, 2026 with Rolldown as its single bundler and Oxc as the compiler. The migration guide puts it in one line: "The Oxc Minifier is now used for JavaScript minification instead of esbuild."

The top-level esbuild option is deprecated now. Vite still converts a handful of its keys for you: jsxInject, include, exclude, the jsx* options and define. That's the whole list. In Vite's source, convertEsbuildConfigToOxcConfig maps exactly those and warns about banner and footer. drop, pure and dropLabels are skipped without a word.

You only get a message when something also sets oxc options. Then Vite prints this and moves on:

Warning printed by vite build
Both esbuild and oxc options were set. oxc options will be used and esbuild options will be ignored. The following esbuild options were set: `{ drop: [ 'console', 'debugger' ] }`

React projects see it because @vitejs/plugin-react 6.3.0 sets oxc options itself. A vanilla project, or one whose plugins never touch oxc, gets no message and the same leak. Framework modules can trigger it too: nuxt-security issue #737 is titled "[Vite 8] Both esbuild and oxc options were set", because nuxt-security 2.6.0 sets esbuild.drop: ['console','debugger'] on your behalf.

The Vite 8 config that removes console.log

The fix moves the option to where the minifier actually reads it, the Rolldown output options:

vite.config.ts
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

// Vite 8: the Oxc minifier inside Rolldown does the dropping
export default defineConfig({
  plugins: [react()],
  build: {
    rolldownOptions: {
      output: {
        minify: {
          compress: {
            dropConsole: true,
            dropDebugger: true,
          },
        },
      },
    },
  },
})

The answers in discussion #22767 are spread across several replies, and one of them has the casing wrong. What I'd pin down before copying anything:

One thing about the shape of output.minify. The Rolldown docs type it as boolean | MinifyOptions | "dce-only". When you set it, your value replaces what Vite would have passed (Vite's build.ts only merges the two when both are objects, which happens in ES library mode). That replace rule explains two surprises further down, where build.minify stops behaving the way you'd expect.

If you haven't touched a Vite config since the early versions, my older intro to Vite covers the dev server and build basics. Most of it still holds. The minifier section doesn't.

I tested every variant on a fresh Vite 8.3.8 React app

I didn't want to trust a config just because the build passed, so I counted calls in the output. On this server I have Node v25.2.1 and npm 11.6.2. I scaffolded a React TS app with create-vite 9.3.4, which pulled in Vite 8.3.8, Rolldown 1.2.19, @vitejs/plugin-react 6.3.0, React 19.3.1 and TypeScript 7.0.2. There's no browser here, so I didn't check DevTools. I checked the built JS in dist instead, which is what your users download anyway.

First, a file that calls every console method I care about, plus two edge cases: an optional-chain call and a log whose argument has a side effect.

src/debug.ts
// Lab test code: every console method we care about, plus edge cases.
function sideEffect(): string {
  const w = window as unknown as { __labSide?: number }
  w.__labSide = (w.__labSide ?? 0) + 1
  return 'side'
}

export function runDebug(user: { id: number; token: string }) {
  console.log('LAB-LOG', user)
  console.debug('LAB-DEBUG')
  console.info('LAB-INFO')
  console.warn('LAB-WARN')
  console.error('LAB-ERROR')
  console?.log('LAB-OPTIONAL')
  console.log('LAB-SIDE', sideEffect())
  debugger
}

I called it from main.tsx with runDebug({ id: 1, token: 'abc123' }). Every build ran through a small script that copies a config into place, runs npx vite build, then counts console.* calls and my LAB-* markers in dist (the counter is in the CI section below). One note on the numbers: console.error starts at 7 because React's production bundle has 6 of its own.

Baseline and the Vite 7 config

The default config shipped everything. The minified output had my token object sitting in plain text:

Output: default config, grep of dist
dist/assets/index-DP0oPoSa.js   222.74 kB │ gzip: 69.42 kB

✓ built in 567ms
...
abSide=(e.__labSide??0)+1,`side`}function v(e){console.log(`LAB-LOG`,e),console.debug(`LAB-DEBUG`),console.info(`LAB-INFO`),console.warn(`LAB-WARN`),console.error(`LAB-ERROR`),console?.log(`LAB-OPTIONAL`),console.log(`LAB-SIDE`,_())}v({id:1,token:`abc123`}),(0,u.createRoot)(document.getElementById(`root`)).render((0,h.jsx)(l.

Then I added the classic answer, esbuild: { drop: ['console', 'debugger'] }, next to the React plugin:

Terminal: esbuild.drop on Vite 8.3.8
$ npx vite build   # config: configs/B-esbuild-drop.ts
Both esbuild and oxc options were set. oxc options will be used and esbuild options will be ignored. The following esbuild options were set: `{ drop: [ 'console', 'debugger' ] }`
vite v8.3.8 building client environment for production...
transforming...
✓ 21 modules transformed.
...
dist/assets/index-DP0oPoSa.js   222.74 kB │ gzip: 69.42 kB

✓ built in 333ms
exit code: 0
$ node ../scripts/count-console.mjs dist
files: 1, bytes: 222743
┌───────────────┬────────┐
│ (index)       │ Values │
├───────────────┼────────┤
│ console.log   │ 3      │
│ console.debug │ 1      │
│ console.info  │ 1      │
│ console.warn  │ 1      │
│ console.error │ 7      │
│ LAB-LOG       │ 1      │
...

Same file hash as the baseline, index-DP0oPoSa.js. The option had zero effect. When I removed the React plugin and kept only esbuild.drop, the warning went away too, and the bundle was still identical. That's the version that bites people: exit code 0, no warning, logs in production.

The snake_case trap

Next I tried the Terser-style keys, drop_console: true and drop_debugger: true, inside the Oxc compress object. Rolldown complains, but the build still passes:

Terminal: snake_case keys
$ npx vite build   # config: configs/E-snake-case.ts
vite v8.3.8 building client environment for production...
Warning: Invalid output options (1 issue found)
- For the "minify.compress". Invalid type: Expected (boolean | Object) but received Object.
transforming...
✓ 21 modules transformed.
...
dist/assets/index-DP0oPoSa.js   222.74 kB │ gzip: 69.42 kB

✓ built in 287ms
exit code: 0

"Expected (boolean | Object) but received Object" is a confusing message for "unknown key". In CI, nobody reads it. Nothing was removed.

The camelCase fix

With the dropConsole config from the previous section:

Terminal: dropConsole build
$ npx vite build   # config: configs/D-dropconsole.ts
...
dist/assets/index-DbMQ5lvq.js   222.30 kB │ gzip: 69.21 kB

✓ built in 254ms
exit code: 0
$ node ../scripts/count-console.mjs dist
files: 1, bytes: 222303
┌───────────────┬────────┐
│ (index)       │ Values │
├───────────────┼────────┤
│ console.log   │ 1      │
│ console.debug │ 0      │
│ console.info  │ 0      │
│ console.warn  │ 0      │
│ console.error │ 0      │
│ LAB-LOG       │ 0      │
│ LAB-DEBUG     │ 0      │
│ LAB-INFO      │ 0      │
│ LAB-WARN      │ 0      │
│ LAB-ERROR     │ 0      │
│ LAB-OPTIONAL  │ 1      │
│ LAB-SIDE      │ 0      │
│ __labSide     │ 0      │
│ debugger      │ 0      │
└───────────────┴────────┘

Almost clean. One console.log survived, and a grep showed which one:

Result: what's left of runDebug
function _(e){console?.log(`LAB-OPTIONAL`)}_({id:1,token:`abc123`}),(0,u.createRoot)(document.getEle

Three things in that one line. The optional-chain call is still there. The {id:1,token:'abc123'} object is still in the bundle, because it's an argument to runDebug, not to console.log. And all 7 console.error calls are gone, React's included. The JS chunk went from 222.74 kB to 222.30 kB (gzip 69.42 to 69.21 kB), and npm run build with tsc -b first gave the same hash.

The last failure was self-inflicted. I switched to build.minify: 'terser' before installing it:

Terminal: terser not installed
✗ Build failed in 187ms
error during build:
Build failed with 1 error:

[plugin vite:terser]
Error: terser not found. Since Vite v3, terser has become an optional dependency. You need to install it.
...
exit code: 1

npm install -D terser fixed it (it installed 5.51.2). That run, and a few stranger ones, are in the next section.

build.minify terser, false or oxc: which one wins?

The output.minify object wins, whatever build.minify says. In Vite's build.ts, build.minify: 'terser' becomes Rolldown output.minify: false and build.minify: false becomes 'dce-only', but a user-provided object replaces either value. So Oxc still runs. I measured each combination on the same app:

Configlog / debug / info / warn / errorconsole?.log leftJS (gzip)Build
Default3 / 1 / 1 / 1 / 7yes222.74 kB (69.42)567ms
dropConsole object1 / 0 / 0 / 0 / 0yes222.30 kB (69.21)254ms
Terser, drop_console: ['log', 'info', 'debug']0 / 0 / 0 / 1 / 7no222.38 kB (70.16)4.88s
minify: 'terser' + dropConsole object1 / 0 / 0 / 0 / 0yes220.65 kB (69.47)4.03s
minify: false + dropConsole object1 / 0 / 0 / 0 / 0yes224.93 kB (69.66)404ms

The Terser-plus-object row is the one to stare at. Both minifiers ran: Oxc dropped every console call, including the console.error calls Terser alone had kept, and then vite:terser spent 3.8s on the chunk anyway. If you inherited a config with minify: 'terser' and someone added the Oxc block on top, you're paying for two minifiers and the Terser settings don't decide what gets dropped.

I was more surprised by the minify: false row. Console calls were still dropped and the JS was still mangled, but CSS lost its minification (4.10 kB went to 5.06 kB) and the JS kept its /* @__PURE__ */ comments across 58 lines. So minify: false plus the object doesn't mean "no minification", it means "Oxc on JS, nothing on CSS".

Vite's docs say the Oxc minifier is "30 ~ 90x faster than terser and only 0.5 ~ 2% worse compression". My single runs aren't a benchmark, but Terser took 4.88s against 254ms here, and its gzip size came out larger, not smaller. I didn't test build.minify: 'esbuild'. It's deprecated in Vite 8, and like Terser it needs its own devDependency: one maplibre-geoman issue notes "you do need to add esbuild as a dependency now with vite v8 for this to work".

Keeping console.error while dropping console.log

People have asked this since 2023 in Vite discussion #7920: "If I want to remove console.log and keep console.error, so how shall we do?" On Vite 8, dropConsole can't do it. It's a boolean, and the Rolldown typings describe it as "Pass true to discard calls to console.*". There's no array form like Terser's.

dropConsole also deletes React's error reporting

In my build, dropConsole took console.error from 7 to 0. Six of those were inside React's production bundle. If you ever ask a user to open DevTools and send you the red text, there won't be any.

What works instead is marking only the noisy methods as pure functions. A pure call whose result isn't used gets removed by the minifier, and everything you didn't list stays:

vite.config.ts (keep warn and error)
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

// Keep console.error/warn: mark only log/debug/info as pure instead of dropConsole
export default defineConfig({
  plugins: [react()],
  build: {
    rolldownOptions: {
      output: {
        minify: {
          compress: {
            treeshake: {
              manualPureFunctions: ['console.log', 'console.debug', 'console.info'],
            },
          },
        },
      },
    },
  },
})

The Oxc docs describe manualPureFunctions, but I couldn't find anyone confirming that Vite passes it through to the minifier. It does: Rolldown 1.2.19 accepted it without a warning. The counts came out at 0 / 0 / 0 / 1 / 7, so console.warn and all 7 console.error calls stayed. It also caught the console?.log call that dropConsole missed. Here's my function after the build:

Result: manualPureFunctions build
function _(){let e=window;return e.__labSide=(e.__labSide??0)+1,`side`}function v(e){console.warn(`LAB-WARN`),console.error(`LAB-ERROR`),_()}

Look at the _() at the end. That was console.log('LAB-SIDE', sideEffect()). Pure marking removes the call but keeps any argument that has side effects. The Oxc docs spell out the difference: with dropConsole, "Dropping a call also drops its arguments and their side effects", and manualPureFunctions: ['console'] is their suggestion when you want to retain them. My dropConsole build matched that: sideEffect() vanished along with the log. Which behavior you want depends on your code. If a log argument does real work (incrementing a counter, calling a function you need), dropConsole silently changes what your app does. I'd rather not log things with side effects at all, but pure marking is the safer default when you don't know your codebase well.

Terser's drop_console: ['log', 'info', 'debug'] gave the same 0 / 0 / 0 / 1 / 7 counts, with one difference: it dropped sideEffect() too (__labSide went to 0), the way dropConsole does. If you're already on Terser, it's fine. I wouldn't switch to it just for this, given the 4.88s build.

What dropConsole leaves behind

Optional-chain calls are the first gap. The Oxc docs say it plainly: dropConsole "does not remove optional-chain calls". If grep -r "console?\." src finds anything in your codebase, add a pure marker next to dropConsole:

vite.config.ts (strip everything)
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

// Strip everything: dropConsole, plus pure-marking to catch console?.log
export default defineConfig({
  plugins: [react()],
  build: {
    rolldownOptions: {
      output: {
        minify: {
          compress: {
            dropConsole: true,
            dropDebugger: true,
            treeshake: {
              manualPureFunctions: ['console.log'],
            },
          },
        },
      },
    },
  },
})

That build counted 0 for every method and every marker, and grep -c 'abc123' on the chunk printed 0. With nothing left inside runDebug, the minifier dropped the call and the token object with it.

Which brings up the second gap: data. Removing console.log(user) doesn't remove user. In the plain dropConsole build, {id:1,token:'abc123'} was still in the JS because another function received it. Stripping logs keeps your console quiet. It doesn't keep secrets out of the bundle, so don't treat it as a security control.

Wrappers are the third. dropConsole only matches direct console.* calls, so a logger.debug() call site isn't one of them. The call and its arguments stay in the bundle. The Oxc docs suggest labeled statements for this case: write DEV: console.log("foo") and set dropLabels: ["DEV"]. I haven't tested dropLabels. If you build your own logger, a Proxy around console is another route people use, but then the minifier can't help you and you're relying on runtime checks.

SSR is the last one, and the build output surprised me. build.minify defaults to false for SSR, so the default server build kept every console call and even the debugger statement:

Output: SSR build, default config vs dropConsole config
$ npx vite build --ssr src/debug.ts --outDir dist-ssr
vite v8.3.8 building ssr environment for production...
...
dist-ssr/debug.js  0.39 kB │ gzip: 0.24 kB
...
function runDebug(user) {
	console.log("LAB-LOG", user);
	...
	console?.log("LAB-OPTIONAL");
	console.log("LAB-SIDE", sideEffect());
	debugger;
}

The same command with the dropConsole config:

Output: SSR build with dropConsole
dist-ssr/debug.js  0.06 kB │ gzip: 0.08 kB

✓ built in 31ms
exit code: 0
$ cat dist-ssr/debug.js
function e(e){console?.log(`LAB-OPTIONAL`)}export{e as runDebug};

Setting rolldownOptions.output.minify applied to the SSR build too: minified, consoles dropped. Whether you want that is your call. Server logs usually go somewhere useful, so I'd leave SSR alone unless you have a reason. The commenter in the nuxt-security thread scoped it to the browser build with vite.$client.build.rolldownOptions.output.minify.compress and went from 25 console.* calls to 0 on Nuxt 4.6.2 with Vite 8.3.5.

A CI check that fails when console.log reaches dist

Every broken config in my lab exited with code 0. That's the real problem with this upgrade: nothing fails. So I don't trust the config alone. I scan the output after the build and fail the job if a method I banned shows up. This is the script I used for all the counts above:

scripts/count-console.mjs
#!/usr/bin/env node
// Usage: node count-console.mjs <distDir> [--fail-on=log,debug]
// Counts console.* calls and lab markers in built JS. Exits 1 if a method listed in --fail-on is found.
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { join } from 'node:path'

const dist = process.argv[2] ?? 'dist'
const failArg = process.argv.find((a) => a.startsWith('--fail-on='))
const failOn = failArg ? failArg.slice('--fail-on='.length).split(',') : []

function jsFiles(dir) {
  return readdirSync(dir).flatMap((name) => {
    const p = join(dir, name)
    if (statSync(p).isDirectory()) return jsFiles(p)
    return /\.(m?js|cjs)$/.test(name) ? [p] : []
  })
}

const files = jsFiles(dist)
const code = files.map((f) => readFileSync(f, 'utf8')).join('\n')
const count = (re) => (code.match(re) ?? []).length

const methods = ['log', 'debug', 'info', 'warn', 'error']
const calls = {}
for (const m of methods) {
  calls[`console.${m}`] = count(new RegExp(`\\bconsole\\s*(?:\\?\\.|\\.)\\s*${m}\\b`, 'g'))
}
const markers = {}
for (const m of ['LAB-LOG', 'LAB-DEBUG', 'LAB-INFO', 'LAB-WARN', 'LAB-ERROR', 'LAB-OPTIONAL', 'LAB-SIDE', '__labSide']) {
  markers[m] = count(new RegExp(m.replace('-', '\\-'), 'g'))
}
markers['debugger'] = count(/\bdebugger\b/g)

console.log(`files: ${files.length}, bytes: ${code.length}`)
console.table({ ...calls, ...markers })

const failed = failOn.filter((m) => calls[`console.${m}`] > 0)
if (failed.length) {
  console.error(`FAIL: found ${failed.map((m) => `console.${m} (${calls[`console.${m}`]})`).join(', ')} in ${dist}`)
  process.exit(1)
}
if (failOn.length) console.log(`OK: no console.${failOn.join('/console.')} in ${dist}`)

The LAB-* markers are only for my test file, so delete that loop in your project. The regex counts console?.log as well as console.log, which matters. Here's what node ../scripts/count-console.mjs dist --fail-on=log,debug,info printed against three builds:

Output: default, dropConsole, manualPureFunctions
# default config
files: 1, bytes: 222743
...
FAIL: found console.log (3), console.debug (1), console.info (1) in dist
exit code: 1

# dropConsole config
files: 1, bytes: 222303
...
FAIL: found console.log (1) in dist
exit code: 1

# manualPureFunctions config
files: 1, bytes: 222613
...
OK: no console.log/console.debug/console.info in dist
exit code: 0

The middle result is the reason I'd run this even with a correct config. dropConsole looked done, and the check still caught the console?.log survivor. It's a text match, though, so a dependency that has the string console.log inside a message will also count. If that happens, scope the check or allow-list the file rather than deleting the check.

Before you ship the upgrade, I'd go through this list:

My post on setting up CI/CD with GitHub Actions covers where a step like that goes in a workflow. If you're migrating from webpack instead of an older Vite, the drop options live in a different place again, and my webpack configuration guide shows where TerserPlugin sits in optimization.minimizer, which is where its drop_console setting would go. And if this same upgrade PR also moved you to TypeScript 7 (the scaffolder gave me 7.0.2), the typescript-eslint ERESOLVE fix might be your next stop.

FAQ

Is it dropConsole or drop_console in Vite 8?

It's dropConsole, in camelCase, under build.rolldownOptions.output.minify.compress. The snake_case drop_console belongs to Terser. If you put drop_console in the Oxc object, Vite 8.3.8 prints Invalid output options, the build still exits 0, and every console call ships. A reply in Vite discussion #22767 claimed snake_case was right and was corrected a few days later.

Do I still need terser to drop console in Vite 8?

No. The default Oxc minifier handles it with dropConsole or manualPureFunctions, and you don't install anything extra. Terser is still an option if you prefer its drop_console array, but it's an optional dependency you have to add with npm install -D terser, and in my lab the Terser build took 4.88s against 254ms for Oxc.

Should I set build.minify: 'oxc' as well as rolldownOptions?

You don't need to. 'oxc' is already the default for client builds in Vite 8, so adding it changes nothing. A commenter in discussion #22767 got byte-identical output with and without it on Vite 8.1.0. The compress options under build.rolldownOptions.output.minify are what actually remove the calls.

How do I fix "Both esbuild and oxc options were set" in Vite 8?

Delete the esbuild block from your config and move each option to its Oxc home. JSX settings go under oxc.jsx, and drop goes to build.rolldownOptions.output.minify.compress. The warning means a plugin, often @vitejs/plugin-react, already set oxc options, so Vite ignores your esbuild settings. If a framework module sets esbuild for you, as nuxt-security 2.6.0 does, you can't just delete the block, so add the Oxc compress options in your own config instead.

Does dropConsole remove console.log from node_modules dependencies?

Yes, for anything that ends up in the client bundle. The minifier runs on the final chunks, so it doesn't care where the code came from. In my lab it removed six console.error calls from React's own production code. Dependencies that are loaded from a CDN or kept external aren't in your chunks, so they aren't touched.

Vite Rolldown Oxc JavaScript Debugging
Mayur Dabhi

Mayur Dabhi

Full Stack Developer with 5+ years of experience building scalable web applications with Laravel, React, and Node.js.