voize-gmbh / reakt-native-toolkit

Combine React Native with Kotlin Multiplatform (KMP)
Apache License 2.0
124 stars 4 forks source link

[Feature] Improve linking error output #58

Open rocketraman opened 5 months ago

rocketraman commented 5 months ago

The create-react-native-library tool instantiates modules in JavaScript with code that looks like this:

import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
  `The package 'foo' doesn't seem to be linked. Make sure: \n\n` +
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
  '- You rebuilt the app after installing the package\n' +
  '- You are not using Expo Go\n';

const Foo = NativeModules.Foo
  ? NativeModules.Foo
  : new Proxy(
      {},
      {
        get() {
          throw new Error(LINKING_ERROR);
        },
      }
    );

If the module is not linked for some reason, this produces a nice error message. With the toolkit, the generated Typescript code simply tries to dereference the undefined module, which results in much less clear errors like:

Cannot read property 'unsubscribeFromToolkitUseFlow' of null