All jobs

Fix Cannot Find Module @babel/core After a babel-loader Upgrade

Yes. An agent reproduces the build error on babel-loader 8 and 9 with Babel 6, moves the project to @babel/core and preset-env, and opens a PR with the bundle built.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads the build first. In a small webpack project like sym233/core-values-encoder, package.json lists babel-cli, babel-core ^6.26.0, babel-loader ^7.1.2, babel-preset-env ^1.6.1, babel-preset-es2015, babelify and webpack ^3.8.1 as dev dependencies and babel-polyfill as a dependency, with one script, build: webpack -p. .babelrc is {"presets": ["env"]}, webpack.config.js sends ./src/index.js through babel-loader into dist/bundle.js, and src/index.js starts with import "babel-polyfill" before the ES2015 code. The lockfile resolves babel-core 6.26.3, babel-loader 7.1.5 and webpack 3.12.0, and npm run build emits a 96.9 kB bundle.

Then it reproduces the two errors an upgrade produces, since which one appears depends on how far the loader was bumped. npm install babel-loader@8 resolves 8.4.1, whose peer dependencies are @babel/core ^7.0.0 and webpack >=2; the build then fails with Module build failed: TypeError: .../src/index.js: Cannot read properties of null (reading 'bindings'), because the loader hands Babel 7 options to the Babel 6 core still installed. npm install babel-loader@9, which needs --legacy-peer-deps because 9 wants webpack >=5, fails more plainly: Module build failed: Error: Cannot find module '@babel/core', followed by the loader's own hint, babel-loader@9 requires Babel 7.12+ (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'. The current release, 10.1.1, asks for webpack >=5.61.0 and Node 18.20, 20.10 or 22 and later.

The fix is the Babel 7 move the loader is asking for, not a downgrade. The agent removes babel-cli, babel-core, babel-preset-env, babel-preset-es2015, babelify and babel-polyfill, installs @babel/core 7.29.13, @babel/preset-env 7.29.7 and babel-loader 8.4.1, the last major that supports webpack 3, plus core-js 3.51.0 and regenerator-runtime to replace the polyfill. .babelrc becomes [["@babel/preset-env", {"useBuiltIns": "entry", "corejs": 3}]], and the first line of src/index.js becomes import "core-js/stable" and import "regenerator-runtime/runtime". npm run build then emits a 160 kB bundle with no class or const left in it, larger than before because core-js 3's entry polyfill set is bigger than babel-polyfill's.

The agent also tries the step past that and reports it: with babel-loader@9 on webpack 3 the build fails with Module build failed: TypeError: this.getOptions is not a function, the loader API webpack 5 added, so 9 and 10 wait on a webpack upgrade that the pull request names as the next change rather than folding into this one.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This webpack project fails with \"Cannot find module '@babel/core'\" after upgrading babel-loader. Read package.json, the lockfile, .babelrc, webpack.config.js and the entry file first. Install the locked versions and run the build once to show it passes; then install babel-loader 8 and 9 in turn and quote each build error, including the loader's own hint. Move the project from Babel 6 to Babel 7: replace babel-core and its presets with @babel/core and @babel/preset-env, replace babel-polyfill with core-js and regenerator-runtime, rewrite .babelrc, and pick the newest babel-loader major that the project's webpack supports. Run the build again and report the bundle size and whether ES2015 syntax remains in it. If a newer loader needs a webpack upgrade, say so and leave that for a separate change. Open a pull request that quotes the failing and passing builds.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request touching package.json, the lockfile, .babelrc and src/index.js: six Babel 6 packages removed, @babel/core, @babel/preset-env, babel-loader 8, core-js 3 and regenerator-runtime added, the preset rewritten with useBuiltIns: "entry", and the polyfill import replaced by the two core-js entries. The description quotes the bindings error from babel-loader 8 and the Cannot find module '@babel/core' error with its hint from babel-loader 9, the bundle sizes before and after, a check that no class or const survives in the output, and the this.getOptions is not a function error that shows babel-loader 9 needs webpack 5.

A reviewer checks that the preset targets did not change, that the polyfill replacement covers what babel-polyfill covered, and that nothing in webpack.config.js moved. The run's record holds every install and build with its full output, so each error can be read rather than taken on trust.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run bumps the loader, runs the build and opens one pull request on its own branch when the bundle no longer builds; a week already on the newest loader the project's webpack supports opens nothing, and a week where the bundle cannot be made to build ends needs_review with the error attached.

The same body works from your own code with POST /o/{org}/sessions and an API key when a dependency bot's babel-loader bump turns CI red; send a request_id that is a UUID v5 of the bot's pull request number so a retried start returns the same run, and the key's webhook_url receives run.completed or run.failed with the session URL when it ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

The loader's error names a package, but the fix is a toolchain move with six removals, five additions and two files rewritten, and the only proof that it is complete is a bundle that builds and runs the same code. The agent does the whole move in its sandbox, builds at every step and keeps each command with its output in the run's record, so the pull request shows which loader major fits which webpack instead of asserting it.

Old build chains also hide a second cliff behind the first. Getting past @babel/core lands on this.getOptions, which is a webpack major away. The agent walks up to that edge, reports it with the exact error, and stops, so the reviewer gets one change they can merge today and a named next step rather than a pull request that rewrote the bundler too.

Frequently asked questions

Why does babel-loader 8 fail with a different error than 9?

babel-loader 8 still loads whatever babel-core resolves to and passes it Babel 7 options; against the Babel 6 package that ends in Cannot read properties of null (reading 'bindings'). babel-loader 9 requires @babel/core by name and fails to find it, which is why its message carries the hint to install babel-loader@7 for Babel 6.

Can the project stay on Babel 6 with babel-loader 7?

Yes, and the hint says so, but Babel 6 and babel-loader 7 get no fixes. The prompt asks for the Babel 7 move because it is what every later loader expects; a reviewer who only wants the build green again can pin babel-loader@7 instead, and the pull request says that is the one-line alternative.

Why did the bundle grow?

babel-polyfill wrapped core-js 2; the replacement imports core-js/stable with useBuiltIns: "entry", which pulls core-js 3's larger set. Switching to useBuiltIns: "usage" lets preset-env add only the polyfills the code uses, which the pull request suggests as a follow-up once a browserslist target is chosen.

Will the agent upgrade webpack too?

Only if asked. babel-loader 9 and 10 need webpack 5, and the agent shows that boundary with the this.getOptions error, then leaves the bundler alone so the change stays reviewable. Ask for the webpack 5 migration in the prompt and it becomes part of the same run.

More jobs like this: Upgrade dependencies weekly

Keep reading