[Metro 0.84.x] Silent catch in Bundler._initializedPromise causes misleading `Cannot read properties of undefined (reading 'transformFile')` instead of the real error

Open Beginner friendly
#1,808 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript
Domain
build-system

Research direction

Start in metro/src/Bundler.js and inspect the _initializedPromise catch path described in the issue. Reproduce the transformer-construction failure with a missing module if possible, then verify that the original error reaches the bundling output instead of a later transformFile error; add or update focused coverage if the repository has a relevant Bundler test.

Written by the indexing model from the issue text.

Description

Metro version: 0.84.4
Expo SDK version: 57.0.11
Node.js version: 22.16.0

Description

When Metro's Bundler fails to construct its Transformer (e.g. due to a MODULE_NOT_FOUND error in getTransformCacheKey), the actual error is silently caught and swallowed. As a result, this._transformer remains undefined, and any subsequent bundle request produces a completely unrelated and misleading error:

TypeError: Cannot read properties of undefined (reading 'transformFile')
    at Bundler.transformFile (metro/src/Bundler.js:55:30)

This makes debugging extremely difficult because the real cause of the failure (e.g. a missing Babel preset) is never surfaced to the developer.

Root Cause

In metro/src/Bundler.js, the _initializedPromise is defined as:

this._initializedPromise = this._depGraph
  .ready()
  .then(() => {
    this._transformer = new _Transformer.default(config, { ... });
  })
  .catch((error) => {
    console.error("Failed to construct transformer: ", error);
    config.reporter.update({ type: "transformer_load_failed", error });
    // Error is NOT re-thrown promise resolves as undefined
  });

The catch handler logs the error but does not re-throw it, so _initializedPromise resolves successfully even when _transformer was never assigned. When Bundler.transformFile later calls await this.ready() (which awaits _initializedPromise), it returns without error — and then immediately crashes on this._transformer.transformFile(...).

Expected Behavior

The real error (e.g. Cannot find module 'babel-preset-expo') should propagate and be shown to the developer immediately, either as a clear startup failure or as the error message in the bundling output.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react/metro

All issues in react/metro

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.