diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ed1743166..c88d5469bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Fixes - Vendor `metro/countLines` function to avoid issues with the private import ([#5185](https://github.com/getsentry/sentry-react-native/pull/5185)) +- Fix baseJSBundle and bundleToString TypeErrors with Metro 0.83.2 ([#5206](https://github.com/getsentry/sentry-react-native/pull/5206)) ## 7.1.0 diff --git a/packages/core/src/js/tools/vendor/metro/utils.ts b/packages/core/src/js/tools/vendor/metro/utils.ts index 5b9ae21049..290983b6c3 100644 --- a/packages/core/src/js/tools/vendor/metro/utils.ts +++ b/packages/core/src/js/tools/vendor/metro/utils.ts @@ -31,13 +31,19 @@ import type * as sourceMapStringType from 'metro/private/DeltaBundler/Serializer import type * as bundleToStringType from 'metro/private/lib/bundleToString'; import type { MetroSerializer } from '../../utils'; -let baseJSBundle: typeof baseJSBundleType; +let baseJSBundleModule: any; try { - baseJSBundle = require('metro/private/DeltaBundler/Serializers/baseJSBundle'); -} catch (e) { - baseJSBundle = require('metro/src/DeltaBundler/Serializers/baseJSBundle'); + baseJSBundleModule = require('metro/private/DeltaBundler/Serializers/baseJSBundle'); +} catch { + baseJSBundleModule = require('metro/src/DeltaBundler/Serializers/baseJSBundle'); } +const baseJSBundle: typeof baseJSBundleType = + typeof baseJSBundleModule === 'function' + ? baseJSBundleModule + : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + baseJSBundleModule?.baseJSBundle ?? baseJSBundleModule?.default; + let sourceMapString: typeof sourceMapStringType; try { // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -52,13 +58,19 @@ try { } } -let bundleToString: typeof bundleToStringType; +let bundleToStringModule: any; try { - bundleToString = require('metro/private/lib/bundleToString'); -} catch (e) { - bundleToString = require('metro/src/lib/bundleToString'); + bundleToStringModule = require('metro/private/lib/bundleToString'); +} catch { + bundleToStringModule = require('metro/src/lib/bundleToString'); } +const bundleToString: typeof bundleToStringType = + typeof bundleToStringModule === 'function' + ? bundleToStringModule + : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + bundleToStringModule?.bundleToString ?? bundleToStringModule?.default; + type NewSourceMapStringExport = { // Since Metro v0.80.10 https://github.com/facebook/metro/compare/v0.80.9...v0.80.10#diff-1b836d1729e527a725305eef0cec22e44605af2700fa413f4c2489ea1a03aebcL28 sourceMapString: typeof sourceMapString;