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

Error on reload: ERROR Invariant Violation: Failed to call into JavaScript module method RCTEventEmitter.receiveEvent().. #42640

Closed
skinnynpale opened this issue Jan 24, 2024 · 18 comments
Labels
Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@skinnynpale
Copy link

skinnynpale commented Jan 24, 2024

Description

if you reload the application from the simulator (using the hot button), we get the following error, if you reload the application from the metro bundler, then there is no such error

ERROR Invariant Violation: Failed to call into JavaScript module method RCTEventEmitter.receiveEvent(). Module has not been registered as callable. Bridgeless Mode: false. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, HMRClient, AppRegistry. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Steps to reproduce

if you reload the application from the simulator (using the hot button), we get the following error, if you reload the application from the metro bundler, then there is no such error

React Native Version

0.73.2

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer, TurboModule - The New Native Module System, JSI - Javascript Interface, Bridgeless - The New Initialization Flow, Codegen

Output of npx react-native info

System:
  OS: macOS 14.2.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 104.56 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v18.19.0/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/skinnynpale/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 3.0.6
    path: /Users/skinnynpale/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.2
    wanted: 0.73.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

ERROR  Invariant Violation: Failed to call into JavaScript module method RCTEventEmitter.receiveEvent(). Module has not been registered as callable. Bridgeless Mode: false. Registered callable JavaScript modules (n = 10): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, HMRClient, AppRegistry.          A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

Reproducer

--

Screenshots and Videos

telegram-cloud-photo-size-2-5298888882256991998-w

@skinnynpale skinnynpale added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jan 24, 2024
@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jan 24, 2024
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@cortinico
Copy link
Contributor

if you reload the application from the simulator (using the hot button)

What do you mean with the "hot button" in the simulator?

@skinnynpale
Copy link
Author

if you reload the application from the simulator (using the hot button)

What do you mean with the "hot button" in the simulator?

when I press "R" while in the application, the metro bundler reload is triggered

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 24, 2024
@cortinico
Copy link
Contributor

I've tested this on RN Tester, and the problem doesn't happen. @skinnynpale are you able to create a reproducer of any sort? I suppose this could be related to some 3rd party library you have included.

@skinnynpale
Copy link
Author

I've tested this on RN Tester, and the problem doesn't happen. @skinnynpale are you able to create a reproducer of any sort? I suppose this could be related to some 3rd party library you have included.

Okay, thank you! I'll try

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 29, 2024
@RSNara
Copy link
Contributor

RSNara commented Jan 29, 2024

@skinnynpale, are you running into this issue in Bridgeless mode?

Fabric - The New Renderer, TurboModule - The New Native Module System, JSI - Javascript Interface, Bridgeless - The New Initialization Flow, Codegen

This code should never run in Bridgeless mode! I think you've stumbled onto an interesting bug. Looking forward to the reproducer!

@cortinico cortinico added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Jan 30, 2024
@skinnynpale
Copy link
Author

@skinnynpale, are you running into this issue in Bridgeless mode?

Fabric - The New Renderer, TurboModule - The New Native Module System, JSI - Javascript Interface, Bridgeless - The New Initialization Flow, Codegen

This code should never run in Bridgeless mode! I think you've stumbled onto an interesting bug. Looking forward to the reproducer!

Research has shown that this error is triggered by createStackNavigator. We are thinking about switching to a native stack.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 31, 2024
@skinnynpale
Copy link
Author

@skinnynpale, are you running into this issue in Bridgeless mode?

Fabric - The New Renderer, TurboModule - The New Native Module System, JSI - Javascript Interface, Bridgeless - The New Initialization Flow, Codegen

This code should never run in Bridgeless mode! I think you've stumbled onto an interesting bug. Looking forward to the reproducer!

I'm sorry, we don't have Bridgeless enabled, I thought it was enabled by default in the new architecture

@cortinico
Copy link
Contributor

we don't have Bridgeless enabled, I thought it was enabled by default in the new architecture

Nope it needs to be enabled separately in 0.73
@skinnynpale are you able to create a repro in any form?

@sbin1211
Copy link

sbin1211 commented Feb 2, 2024

we don't have Bridgeless enabled, I thought it was enabled by default in the new architecture

Nope it needs to be enabled separately in 0.73 @skinnynpale are you able to create a repro in any form?

@cortinico it caused by the react-native-screens with @react-navigation/bottom-tabs,

you can reproduce this issue with below repro.
(when you trigger the "reload" inside app, the error happen, but NOT from terminal

https://github.com/sbin1211/RNInvariantViolation.git

@cortinico
Copy link
Contributor

it caused by the react-native-screens with @react-navigation/bottom-tabs,

Great, can we open an issue against react-native-screens and link it here?

@sbin1211
Copy link

sbin1211 commented Feb 3, 2024

it caused by the react-native-screens with @react-navigation/bottom-tabs,

Great, can we open an issue against react-native-screens and link it here?

sure. @cortinico please help to link it. i don't know which side (RN or RNScreens) cause this issue.

@cortinico
Copy link
Contributor

sure. @cortinico please help to link it.

Please create the issue there, and post it here afterwards

@wcastand
Copy link

i'm seeing this on android in my production app logs. did anyone had a chance to fix the issue on their side by any chance?
issue on native-screen closed with no solution either :/

@alextbogdanov
Copy link

i'm seeing this on android in my production app logs. did anyone had a chance to fix the issue on their side by any chance? issue on native-screen closed with no solution either :/

I'm having the same issue on ios whenever I open the expo menu in the app

@cortinico
Copy link
Contributor

Closing because of:
software-mansion/react-native-screens#2027 (comment)

@cortinico cortinico removed Needs: Triage 🔍 Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels Aug 2, 2024
@HeXiuLian
Copy link

Solution:
RNSScreen.mm

@implementation RNSScreenView {
  __weak RCTBridge *_bridge;
}

#ifdef RCT_NEW_ARCH_ENABLED
- (instancetype)initWithFrame:(CGRect)frame
{
  if (self = [super initWithFrame:frame]) {
    static const auto defaultProps = std::make_shared<const facebook::react::RNSScreenProps>();
    _props = defaultProps;
    _reactSubviews = [NSMutableArray new];
    _bridge = [RCTBridge currentBridge];
    [self initCommonProps];
  }

  return self;
}
#endif // RCT_NEW_ARCH_ENABLED

- (void)notifyTransitionProgress:(double)progress closing:(BOOL)closing goingForward:(BOOL)goingForward
{
#ifdef RCT_NEW_ARCH_ENABLED
  if (_eventEmitter != nullptr) {
    std::dynamic_pointer_cast<const facebook::react::RNSScreenEventEmitter>(_eventEmitter)
        ->onTransitionProgress(facebook::react::RNSScreenEventEmitter::OnTransitionProgress{
            .progress = progress, .closing = closing ? 1 : 0, .goingForward = goingForward ? 1 : 0});
  }
  RNSScreenViewEvent *event = [[RNSScreenViewEvent alloc] initWithEventName:@"onTransitionProgress"
                                                                   reactTag:[NSNumber numberWithInt:self.tag]
                                                                   progress:progress
                                                                    closing:closing
                                                               goingForward:goingForward];
  if (_bridge) {
    [_bridge.eventDispatcher sendEvent:event];
  } else {
    [[RCTBridge currentBridge].eventDispatcher sendEvent:event];
  }
  
  
#else
  if (self.onTransitionProgress) {
    self.onTransitionProgress(@{
      @"progress" : @(progress),
      @"closing" : @(closing ? 1 : 0),
      @"goingForward" : @(goingForward ? 1 : 0),
    });
  }
#endif
}

@alextbogdanov
Copy link

Create a pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

7 participants