14 C
London
Tuesday, October 24, 2023

React-Native ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., “myApp” has not been registered. iOS solely


We face points when attempting to construct our app on iOS solely.
All packages are updated, it builds completely on Android, however iOS will construct efficiently but throw the error:

ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., js engine: hermes LOG Operating "myApp" with {"rootTag":41,"initialProps":{}} ERROR Invariant Violation: "myApp" has not been registered. This will occur if: * Metro (the native dev server) is run from the flawed folder. Verify if Metro is working, cease it and restart it within the present mission. * A module didn't load as a result of an error and `AppRegistry.register element` wasn't known as., js engine: hermes

We’ve tried deleting the Pods, Podfile.lock, deleting node modules, npm set up –force, pod set up, pod replace, even pod deintegrate, pod init, all the things we discovered a bit in every single place on Google, nothing ever labored. We’re certain of the app identify “myApp” (a placeholder for privateness :)), as you possibly can see within the following information:

/////// Index.js /**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';

AppRegistry.registerComponent('myApp', () => App);
/////// bundle.json
{
  "identify": "myApp",
  "model": "1.0.0",
  "personal": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios --simulator="iPhone 14"",
    "clear": "rm -rf node_modules && npm i",
    "hard-clean-ios": "cd ios && rm -rf Pods && rm -rf construct && pod cache clear --all && pod set up && cd ..",
    "hard-clean-android": "rm -rf node_modules && npm i && cd android && ./gradlew clear && cd ..",
    "delete-cache": "watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-* && rm -rf node_modules/ && npm cache clear --force && npm set up && npm begin -- --reset-cache",
    "lint": "eslint .",
    "begin": "react-native begin",
    "check": "jest",
    "clear:ios": "rm -rf ios/construct"
  },
  "reactNativePermissionsIOS": [
    "BluetoothPeripheral",
    "FaceID",
    "LocationAccuracy",
    "LocationAlways",
    "LocationWhenInUse"
  ],
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.19.3",
    "@react-native-community/checkbox": "^0.5.16",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-native/metro-config": "^0.74.0",
    "@react-navigation/bottom-tabs": "^6.5.9",
    "@react-navigation/native": "^6.1.8",
    "@react-navigation/native-stack": "^6.9.14",
    "date-fns": "^2.30.0",
    "lottie-react-native": "^6.3.1",
    "second": "^2.29.4",
    "react": "18.2.0",
    "react-native": "0.72.4",
    "react-native-base64": "^0.2.1",
    "react-native-ble-plx": "^3.0.0",
    "react-native-bluetooth-state-manager": "^1.3.5",
    "react-native-config": "^1.5.1",
    "react-native-date-picker": "^4.3.3",
    "react-native-device-info": "^10.11.0",
    "react-native-flash-message": "^0.4.2",
    "react-native-gradle-plugin": "^0.71.19",
    "react-native-location-enabler": "^4.1.1",
    "react-native-permissions": "^3.9.3",
    "react-native-rename": "^3.2.13",
    "react-native-safe-area": "^0.5.1",
    "react-native-safe-area-context": "^4.7.2",
    "react-native-screens": "^3.25.0",
    "react-native-splash-screen": "^3.3.0",
    "react-native-vector-icons": "^9.2.0",
    "react-native-version": "^4.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.23.0",
    "@babel/preset-env": "^7.22.20",
    "@babel/runtime": "^7.23.1",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.3",
    "@sorts/jest": "^29.5.5",
    "@sorts/react": "^18.2.28",
    "@sorts/react-native-base64": "^0.2.0",
    "@sorts/react-native-vector-icons": "^6.4.15",
    "@sorts/react-test-renderer": "^18.0.3",
    "babel-jest": "^29.7.0",
    "eslint": "^8.51.0",
    "jest": "^29.7.0",
    "metro-react-native-babel-preset": "^0.73.9",
    "prettier": "^2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}
////// Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!

# If you're utilizing a `react-native-flipper` your iOS construct will fail when `NO_FLIPPER=1` is ready.
# as a result of `react-native-flipper` relies on (FlipperKit,...) that will probably be excluded
#
# To repair this it's also possible to exclude `react-native-flipper` utilizing a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(course of.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

# use_frameworks!

goal 'myApp' do
  config = use_native_modules!

  permissions_path="../node_modules/react-native-permissions/ios"

  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
  pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"

  # Flags change relying on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming variations of React Native might depend on get_default_flags(), however
    # we make it specific right here to help within the React Native improve course of.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # Allows Flipper.
    #
    # Observe that in case you have use_frameworks! enabled, Flipper is not going to work and
    # it's best to disable the subsequent line.
    :flipper_configuration => flipper_config,
    # An absolute path to your utility root.
    :app_path => "#{Pod::Config.occasion.installation_root}/.."
  )

  # pre_install do |installer|
  #   Pod::Installer::Xcode::TargetValidator.ship(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  
  #   installer.pod_targets.every do |pod|
  #     if pod.identify.eql?('RNPermissions') || pod.identify.start_with?('Permission-')
  #       def pod.build_type;
  #         # Uncomment the road equivalent to your CocoaPods model
  #         # Pod::BuildType.static_library # >= 1.9
  #         # Pod::Goal::BuildType.static_library # < 1.9
  #       finish
  #     finish
  #   finish
  # finish

  ENVFILES = {
  'Debug' => '$(PODS_ROOT)/../../.env.dev',
  'Launch' => '$(PODS_ROOT)/../../.env.prod',
}

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` so as to apply patches
      # mandatory for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    installer.pods_project.targets.every do |goal|
      goal.build_configurations.every do |config|
        if goal.identify == 'react-native-config'
          config.build_settings['ENVFILE'] = ENVFILES[config.name]
        finish
      finish
    finish
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  finish
finish

/////// AppDelegate.mm
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)utility:(UIApplication *)utility didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"oslysolutions";
  // You'll be able to add your customized preliminary props within the dictionary under.
  // They are going to be handed all the way down to the ViewController utilized by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"important" withExtension:@"jsbundle"];
#endif
}

/// This technique controls whether or not the `concurrentRoot`characteristic of React18 is turned on or off.
///
/// @see: https://reactjs.org/weblog/2022/03/29/react-v18.html
/// @be aware: This requires to be rendering on Material (i.e. on the New Structure).
/// @return: `true` if the `concurrentRoot` characteristic is enabled. In any other case, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

@finish

Cannot work out what we’re lacking. Any assist can be superb 🙂

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here