Skip to content
Latchkey

Babel "Cannot find module '@babel/...'" - Fix Missing Presets in CI

Babel tried to load a preset or plugin named in your config and could not find it in node_modules. The config references a package that was never installed - or only installed locally and not declared as a dependency.

What this error means

The build fails with Cannot find module '@babel/preset-env' (or preset-react, a plugin, etc.) referenced from your Babel config. It is deterministic - a missing dependency, not flake.

babel output
Error: Cannot find module '@babel/preset-react'
Require stack:
- /app/node_modules/@babel/core/lib/config/files/plugins.js
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
  at babel.config.js (presets: ['@babel/preset-react'])

Diagnose it: is it resolution, transform, or memory?

Bundler failures in CI fall into three families and the error text often points at the wrong one. A module that resolves on your machine and not on the runner is nearly always case sensitivity or a missing optional dependency; a transform error is a config or version mismatch; and an unexplained kill with no stack is the out-of-memory reaper, not a build error at all.

Terminal
# 1. resolution: does the file exist with EXACTLY that case?
git ls-files | grep -i "the/imported/path"

# 2. transform: what versions is CI actually resolving?
npm ls webpack vite rollup esbuild typescript 2>/dev/null | head -20

# 3. memory: was it killed rather than failed?
#    exit 137 = SIGKILL (OOM). Nothing in the bundler log will explain it.
node --max-old-space-size=4096 node_modules/.bin/vite build

Common causes

Preset/plugin not installed

The config lists a preset (@babel/preset-env, @babel/preset-react, @babel/preset-typescript) or plugin that is not in package.json, so a clean install does not provide it.

Wrong package name or version

A typo, an old babel-preset-* (Babel 6) name on Babel 7, or a major-version mismatch between @babel/core and a preset makes resolution fail.

How to fix it

Install the presets/plugins you reference

Add every preset and plugin named in the Babel config as a dev dependency.

Terminal
npm install -D @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript

Use the correct Babel 7 names

Reference scoped @babel/* packages, matched to your @babel/core major.

babel.config.js
// babel.config.js
module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
}

Make the build reproducible before you debug it

  • Pin the Node major in setup-node and in engines. A bundler that resolves native bindings will pick a different prebuilt binary across majors.
  • Delete node_modules locally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state.
  • Set CI=true locally to reproduce. Several toolchains change behaviour under it, including treating warnings as errors.
  • Exit code 137 is an out-of-memory kill. Raise --max-old-space-size or move to a larger runner rather than searching the bundler config.

How to prevent it

  • Declare every Babel preset/plugin in devDependencies.
  • Install with npm ci so CI matches the lockfile.
  • Keep @babel/core and presets on compatible major versions.

Frequently asked questions

What causes Babel "Cannot find module '@babel/...'"?
There are 2 common causes: preset/plugin not installed and wrong package name or version. The config lists a preset (@babel/preset-env, @babel/preset-react, @babel/preset-typescript) or plugin that is not in package.json, so a clean install does not provide it.
How do I fix Babel "Cannot find module '@babel/...'"?
There are 2 fixes depending on which cause you have: install the presets/plugins you reference and use the correct babel 7 names. Work through them in order, since the first is the most common.
What does Babel "Cannot find module '@babel/...'" actually mean?
The build fails with Cannot find module '@babel/preset-env' (or preset-react, a plugin, etc.) referenced from your Babel config.
How do I stop Babel "Cannot find module '@babel/...'" happening again?
Declare every Babel preset/plugin in devDependencies. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card