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.
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
- Add @babel/core as a devDependency.
- Keep it on the major the consumer requires (7.x).
- Reinstall and re-run the build.
npm install --save-dev @babel/core @babel/cliInstall peer dependencies explicitly
Audit peer requirements so every Babel consumer has its core peer present in CI.
npm ls @babel/coreHow 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 ciso the lockfile installs all required peers.