sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

sentryMetroSerializer cannot read size property of undefined importBundleNames

Open Raraku opened this issue 1 year ago • 2 comments

OS:

  • [ ] Windows
  • [*] MacOS
  • [ ] Linux

Platform:

  • [ *] iOS
  • [ ] Android

SDK:

  • [*] @sentry/react-native (>= 1.0.0)
  • [ *] react-native-sentry (<= 0.43.2)

SDK version: 5.19.0

react-native version: 0.73.1

Are you using Expo?

  • [ ] Yes
  • [ *] No

Are you using sentry.io or on-premise?

  • [* ] sentry.io (SaaS)
  • [ ] on-premise

If you are using sentry.io, please post a link to your issue so we can take a look:

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://[email protected]/...'
  // other options
});

I have the following issue:

Following the docs and using the SentryMetroSerializer made my application fail to build or run locally. This error was first spotted on our eas build ci pipeline and I reproduced it manually in xcode. Run, build and archive operations all fail with this enabled. metro.config.js had the default configuration and wasn't customized in any way, so I replaced it entirely with this

Steps to reproduce:

  • Follow the steps on sentry's website. Replace metro configuration with:
      const {
        createSentryMetroSerializer,
      } = require("@sentry/react-native/dist/js/tools/sentryMetroSerializer");
    
      const config = {
        serializer: {
          customSerializer: createSentryMetroSerializer(),
        },
      };
    
      module.exports = mergeConfig(getDefaultConfig(__dirname), config);```
    
    
    

Actual result:

It produces this undefined error Metro has encountered an error: Cannot read properties of undefined (reading 'size'):


  23 |   const output = [];
  24 |
> 25 |   if (importBundleNames.size) {
     |                         ^
  26 |     const importBundleNamesObject = Object.create(null);
  27 |     importBundleNames.forEach((absolutePath) => {
  28 |       const bundlePath = path.relative(options.projectRoot, absolutePath);

RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0
0x0

Expected result: Metro should bundle the app successfully. I reverted the changes and the application worked immediately.

Raraku avatar Feb 25 '24 15:02 Raraku

Hi @Raraku, thank you for the message, you mentioned EAS Build, what version of React Native and Expo are you using? Can you check what version of metro package is in node_modules/metro of your project?

krystofwoldrich avatar Feb 27 '24 19:02 krystofwoldrich

The cause of the error might be the same as https://github.com/getsentry/sentry-react-native/issues/3622.

krystofwoldrich avatar Feb 27 '24 19:02 krystofwoldrich

Closing this due to inactivity. If this is still an issue feel free to comment here or open a new issue if the context changed.

krystofwoldrich avatar Mar 15 '24 12:03 krystofwoldrich

I had the same issue in a monorepo setup

Fixed by

  1. I had dependency conflicts, had metro-config, metro-react-native-babel-preset and @react-native/metro-config present in my package.json
  • removed old ones (metro-config, metro-react-native-babel-preset)
  • kept official one for latest RN 0.73.6 which is "@react-native/metro-config": "0.73.5"
  1. Ensure metro dependencies are not hoisted and available at package node_modules, not root mono repo node_modules at root package.json add to achieve that

"nohoist": [ "**/@react-native/**", ]

NabeelZanabeet avatar Mar 20 '24 23:03 NabeelZanabeet

@NabeelZanabeet thank you for the hint. In my case the problem was "@react-native-community/cli-plugin-metro": "^9.1.1" that was loading a wrong version of metro-config

alexincore avatar Jul 17 '24 17:07 alexincore