Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require.getModules()returns empty modules list under react-native 76 #1436

Open
dprevost-LMI opened this issue Feb 12, 2025 · 1 comment
Open

Comments

@dprevost-LMI
Copy link
Contributor

dprevost-LMI commented Feb 12, 2025

Description

Since our application has a critical business use case on boot, we had to split code using require to speed up our bundle to load, and that worked really well.
To ensure the expected module loaded stays the same, and our colleague does not start pulling unwanted modules, we have used require.getModules() against some allowed lists to spot any new undesired modules.

However, after upgrading to react-native 0.76.7, require.getModules() returns an empty array list. On react-native 0.75.5, it works well.

On react-native 75 it uses metro v0.80.9.
On react-native 76 it uses metro v0.81.1

I looked at metro issues, and nothing was reported there, so I'm more inclined to believe it is react-native related! Let me know, I can move/open an issue in metro, too, if you think it is more metro-related!

Steps to reproduce

  1. Build start any app
  2. In the index.js add a line like console.log('require.getModules()',require.getModules())
  3. We can observe that it returns an empty list

React Native Version

0.76.7

Affected Platforms

Runtime - Android

Output of npx react-native info

info Fetching system and libraries information...
System:
  OS: macOS 15.2
  CPU: (12) arm64 Apple M2 Pro
  Memory: 2.12 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.4
    path: ~/.nvm/versions/node/v18.20.4/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.4/bin/npm
  Watchman:
    version: 2024.11.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/dprevost/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23726.103.2422.12816248
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.3.3
    path: /Users/dprevost/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react: Not Found
  react-native:
    installed: 0.76.7
    wanted: 0.76.7
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

Below is an example of the loaded module filter on the node_module folder that we would expect to see on 76, but that is empty

 LOG  loaded node_module names [
  "container_autogenerated/index.js",
  "container_autogenerated/config.json",
  "container_autogenerated/appModules.js",
  "development.ts",
  "module.js",
  "src/index.native.js",
  "src/loadingJSTime.ts",
  "src/ignoreErrorsAndWarning.ts",
  "src/environmentUtils.js",
  "src/initSentry.js",
  "../react-native-local-storage/appInfo/index.ts",
  "../react-native-local-storage/src/AppInfo.ts",
  "src/initConfig.ts",
  "config/env.utils.ts",
  "../react-native-utils/environments/environment.model.ts",
  "config/env.constant.ts",
  "../react-native-local-storage/sharedPreferences/index.ts",
  "../react-native-local-storage/src/SharedPreferences.ts",
  "../react-native-utils/environments/index.ts",
  "../react-native-utils/environments/environment.config.ts",
  "container_autogenerated/environment.js",
  "container_autogenerated/buildType.js",
  "src/logs/logs.uuid.ts",
  "../react-native-local-storage/sessionLogger/index.ts",
  "../react-native-local-storage/src/SessionLogger.ts",
  "../react-native-utils/platform/index.ts",
  "../react-native-utils/utils/platform.ts",
  "src/uuid.v4.ts",
  "../react-native-fbt-scripts/init.js",
  "../react-native-fbt-scripts/src/fbtInit.js",
  "../react-native-fbt-scripts/src/getTranslatedInput.js",
  "../react-native-fbt-scripts/src/FbtI18nNativeAssets.js",
  "../react-native-fbt-scripts/src/NativeFbtModule.js",
  "src/devTools/moduleLoaded.js"
]

Reproducer

Soon

Screenshots and Videos

Any pointer on how to troubleshoot would be appreciated since I'm clueless about what to look next!

@react-native-bot
Copy link

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@dprevost-LMI dprevost-LMI changed the title require.getModules() no longer working under react-native 0.76.7 require.getModules()returns empty modules list under react-native 0.76.7 Feb 12, 2025
@dprevost-LMI dprevost-LMI changed the title require.getModules()returns empty modules list under react-native 0.76.7 require.getModules()returns empty modules list under react-native 76 Feb 12, 2025
@cortinico cortinico transferred this issue from facebook/react-native Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants