Repository navigation
fix(react-native): explain a missing native module at import - #82
NathanWalker wants to merge 2 commits into
Conversation
- The TurboModule is looked up with TurboModuleRegistry.get, so importing the package in Expo Go or a build made before it was added no longer raises an uncatchable invariant. isAvailable() reports whether the module is present; init() and the other functions that need it throw an error saying to rebuild. - init() no longer installs into a Worklets runtime on Android, where there is none, so it returns true instead of throwing a message about missing react-native-worklets setup. runOnUI()/installWorklets() on Android say they are iOS only.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
AFIK, if someone installed the library in Expo Go where the native part is missing, throwing an error is the correct behavior and it does not need to be fixed I think.
The other change, making the worklet runtime get installed only on iOS is also not required as we will be adding support for Android in a PR soon. |
Keep failing at import when NativeScriptNativeApi is not in the app binary, but with an error that says the package cannot run in Expo Go and that a build made before the package was added must be rebuilt, instead of React Native's generic TurboModuleRegistry invariant. Drop isAvailable() and the Android-specific init() path.
|
Thanks, agreed on both points. I looked at what comparable libraries do. vision-camera, mmkv, Skia, Nitro and the create-react-native-library template all fail at import when their native module is missing. vision-camera and mmkv add a message that names Expo Go and says to use a development build. So this PR now does only that:
|
Important
Squash merge this PR. The first commit (31932e9) describes isAvailable() and an Android init() change, both removed after review. Use this as the squash commit message (title + body), replacing GitHub's default list of commit messages:
Split out of #77 (item 7 of the "NativeScript bugs" list in ng-native/ng-native#931). Reworked after review: importing the package without its native module still fails at import, but the error now says why.
Summary
TurboModuleRegistry.getEnforcingfails with React Native's generic invariant, which doesn't say what to do. Libraries that cannot run in Expo Go also fail at import, but with a message that names Expo Go and says to rebuild. Examples are react-native-vision-camera, react-native-mmkv, Skia, Nitro and the create-react-native-library template.Removed after review:
isAvailable()and the Android-onlyinit()path. Android Worklets support is coming separately.Evidence
@react-native/codegen's TypeScript parser (RN 0.86.3) still reads the spec: moduleNativeScriptNativeApiwith the same six methods.tsc --strict: importers see the default export asSpec, notSpec | null.index.tsandindex.d.tsmatch the base branch.Merge Danger
Door: two-way
Blast Radius: the import-time error message of
@nativescript/react-nativeThe import still throws in the same situations. Only the message changes.