Skip to content
Latchkey

Vitest "Transform failed with ... error" in CI

Vitest transforms source with esbuild via Vite before running it. A "Transform failed" error means esbuild rejected a file: a syntax error, a TypeScript feature it does not handle, or a file type with no configured loader. The message points at the exact line.

What this error means

The run fails with "Error: Transform failed with 1 error" and an esbuild location, before the test executes.

Vitest
Error: Transform failed with 1 error:
/home/runner/work/app/app/src/foo.ts:12:8: ERROR: Expected ";" but found "const"

Common causes

A syntax error in a transformed file

esbuild parses fast but strictly; a genuine syntax mistake fails the transform with a precise location.

An unsupported feature or missing loader

A TS feature esbuild does not implement (some decorators/const enums setups), or a file type with no loader, cannot be transformed.

How to fix it

Fix the flagged syntax

  1. Open the file and line esbuild names in the error.
  2. Correct the syntax or unsupported construct.
  3. Re-run so the transform succeeds.

Configure esbuild for the feature

For features like decorators, set the appropriate esbuild option, or add a plugin/loader for the file type.

vitest.config.ts
export default defineConfig({
  esbuild: { target: 'es2022' },
})

How to prevent it

  • Lint and type-check before tests so syntax errors surface early.
  • Configure esbuild target/options for the language features you use.
  • Add loaders/plugins for non-standard file types imported by tests.

Frequently asked questions

What causes ""Transform failed with 1 error""?
esbuild parses fast but strictly; a genuine syntax mistake fails the transform with a precise location.
How do I fix "Transform failed with 1 error"?
Fix the flagged syntax

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card