Skip to content
Latchkey

babel Command: Transpile JS in CI

babel transpiles modern JS/TS/JSX down to a target-compatible JavaScript.

The Babel CLI (@babel/cli) compiles modern JavaScript, JSX, and TypeScript into widely supported output. In CI it runs as a library build step, emitting transpiled files and source maps for publishing or further bundling.

Common flags

  • --out-dir DIR / -d DIR - compile a directory into DIR
  • --out-file FILE / -o FILE - compile to a single output file
  • --config-file PATH - use a specific Babel config
  • --extensions .ts,.tsx - file extensions to compile
  • --source-maps / -s - emit source maps (use inline for inline maps)
  • --copy-files - copy non-compilable files to the output dir
  • --ignore "**/*.test.js" - skip matching files

Example in CI

Transpile a TypeScript src tree to a lib directory with source maps:

shell
babel src --out-dir lib --extensions .ts,.tsx --source-maps --copy-files

Common errors in CI

  • Cannot find module '@babel/preset-env' - preset not installed
  • SyntaxError: Unexpected token - missing a preset/plugin for that syntax
  • .babelrc / babel.config.js: Error while loading config - bad config file
  • Error: Cannot resolve plugin X - plugin name typo or not installed

Key takeaways

  • --out-dir builds a tree; --out-file concatenates to one file.
  • List --extensions explicitly when compiling TypeScript/JSX.
  • Most CI failures are missing presets/plugins not in package.json.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →