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.
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
- Open the file and line esbuild names in the error.
- Correct the syntax or unsupported construct.
- 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.
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.