Skip to content
Latchkey

Babel "Cannot find module '@babel/core'" running the CLI in CI

Both @babel/cli and babel-loader require @babel/core as a peer dependency. When core is absent from a clean CI install, invoking Babel fails immediately with a module-resolution error for @babel/core.

What this error means

The build fails with "Cannot find module '@babel/core'" when running babel or when babel-loader initializes in the bundler.

babel
Error: Cannot find module '@babel/core'
babel-loader@8 requires @babel/core@^7.0.0 as a peer dependency.
    at Function._resolveFilename (node:internal/modules/cjs/loader)

Common causes

@babel/core is not declared as a dependency

A peer dependency is not auto-installed; if @babel/core is missing from package.json, a clean CI install never adds it.

Only @babel/cli or babel-loader was installed

Installing the consumer without its core peer leaves the resolution incomplete on the runner.

How to fix it

Install @babel/core alongside the CLI or loader

  1. Add @babel/core as a devDependency.
  2. Keep it on the major the consumer requires (7.x).
  3. Reinstall and re-run the build.
Terminal
npm install --save-dev @babel/core @babel/cli

Install peer dependencies explicitly

Audit peer requirements so every Babel consumer has its core peer present in CI.

Terminal
npm ls @babel/core

How to prevent it

  • Declare @babel/core whenever you use @babel/cli or babel-loader.
  • Keep Babel core and consumers on the same major version.
  • Run npm ci so the lockfile installs all required peers.

Frequently asked questions

What causes ""Cannot find module '@babel/core'""?
A peer dependency is not auto-installed; if @babel/core is missing from package.json, a clean CI install never adds it.
How do I fix "Cannot find module '@babel/core'"?
Install @babel/core alongside the CLI or loader

Related guides

References

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