Skip to content

Commit 1401ae2

Browse files
committed
Fix how bundle IDs are getting defined for individual bundles
1 parent d1bfbde commit 1401ae2

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/core/src/js/tools/sentryMetroSerializer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ export const createSentryMetroSerializer = (customSerializer?: MetroSerializer):
7474
const { code: bundleCode, map: bundleMapString } = await extractSerializerResult(serializerResult);
7575

7676
// Add debug id comment to the bundle
77-
const debugId = determineDebugIdFromBundleSource(bundleCode);
77+
let debugId = determineDebugIdFromBundleSource(bundleCode);
7878
if (!debugId) {
79-
throw new Error(
80-
'Debug ID was not found in the bundle. Call `options.sentryBundleCallback` if you are using a custom serializer.',
81-
);
79+
// For lazy-loaded chunks or bundles without the debug ID module,
80+
// calculate the debug ID from the bundle content.
81+
// This ensures Metro 0.83.2+ code-split bundles get debug IDs.
82+
// That needs to be done because when Metro 0.83.2 stopped importing `BabelSourceMapSegment`
83+
// from `@babel/generator` and defined it locally, it subtly changed the source map output format.
84+
// https://github.com/facebook/metro/blob/main/packages/metro-source-map/src/source-map.js#L47
85+
const hash = crypto.createHash('md5');
86+
hash.update(bundleCode);
87+
debugId = stringToUUID(hash.digest('hex'));
88+
// eslint-disable-next-line no-console
89+
console.log('info ' + `Bundle Debug ID (calculated): ${debugId}`);
8290
}
8391
// Only print debug id for command line builds => not hot reload from dev server
8492
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)