[Metro 0.84.x] Silent catch in Bundler._initializedPromise causes misleading `Cannot read properties of undefined (reading 'transformFile')` instead of the real error
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 696
- Avg merge
- 8m
- Merged PRs (30d)
- 7
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100