React Native: TypeError: _result.isRoot is not a function (it is undefined)
Report a bug
🔎 Search Terms
com.facebook.react.common.JavascriptException: [runtime not ready]: TypeError: _result.isRoot is not a function (it is undefined)
🧩 Context
- Other context you think may be relevant (JS flavor, OS, etc.): Hermes, Expo SDK
~52.0.43and0.76.9, but I can confirm that it also occurs on latest Expo and RN versions (SDK 53 beta and RN 0.79.0)
npmPackages:
@ark/schema: 0.45.9
@ark/util: 0.45.9
arktype: ^2.1.19 => 2.1.19
typescript: ^5.3.3 => 5.8.3
🧑💻 Repro
Link: https://github.com/shovel-kun/expo-arktype-repro
Code
import { type } from "arktype";
const MediaType = type.enumerated("novel", "manga", "anime");
type MediaType = typeof MediaType.infer;
const SourceId = type("(string > 0)#SourceId");
type SourceId = typeof SourceId.infer;
const MediaItem = type({
sourceId: SourceId,
url: "string.url.parse",
type: MediaType,
});
type MediaItem = typeof MediaItem.infer;
const NovelItem = type(MediaItem, "&", {
type: "'novel'",
});
type NovelItem = typeof NovelItem.infer;
const MangaItem = type(MediaItem, "&", {
type: "'manga'",
});
type MangaItem = typeof MangaItem.infer;
const AnimeItem = type(MediaItem, "&", {
type: "'anime'",
});
type AnimeItem = typeof AnimeItem.infer;
// Uncomment me to see an error!
// const AnyMediaItem = type(NovelItem).or(MangaItem).or(AnimeItem);
// type AnyMediaItem = typeof AnyMediaItem.infer;
const exampleAnime = AnimeItem({
sourceId: "1",
type: "anime",
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
});
if (exampleAnime instanceof type.errors) {
// hover out.summary to see validation errors
console.error(exampleAnime.summary);
} else {
console.log(`Hello, ${exampleAnime.sourceId}`);
}
I'm also getting this same issue in react native
started happening when I added a type.match thing with multiple cases
it was something along the lines of
.case({name:"'FlarmError'"}, renderFlarmError)
.case({name:"'GlarError'"}, renderGlarError)
My team is going to make me rip out arktype and use zod or something if this kind of thing keeps happening :(
Took a look at this and tried to get an android dev environment set up, but this is as far as I got in terms of seeing the app's behavior:
I can't see any difference as far as this behavior between the lines being commented or uncommented, and I'm not sure how to actually go about debugging this.
Would love if someone who already has a working react native env and can repro this could take a look at the problem, but if not, I will need more specific instructions to reproduce.
Hi @ssalbdivad, thanks for looking into this.
I believe that's because the app crashes on start.
If you have adb installed, do adb logcat "*:S" ReactNative:V ReactNativeJS:V in the terminal and you can see what crash was logged. Example of logs below:
--------- beginning of main
05-04 19:01:02.160 5001 5076 I ReactNativeJS: Bridgeless mode is enabled
05-04 19:01:02.596 5001 5076 I ReactNativeJS: Hello, 1
05-04 19:01:02.598 5001 5076 I ReactNativeJS: Running "main" with {"rootTag":11,"initialProps":{},"fabric":true}
05-04 19:01:17.701 5001 5076 E ReactNativeJS: TypeError: _result.isRoot is not a function (it is undefined)
05-04 19:01:21.343 5001 5076 W ReactNativeJS: Cannot connect to Metro.
05-04 19:01:21.343 5001 5076 W ReactNativeJS:
05-04 19:01:21.343 5001 5076 W ReactNativeJS: Try the following to fix the issue:
05-04 19:01:21.343 5001 5076 W ReactNativeJS: - Ensure that Metro is running and available on the same network
05-04 19:01:21.343 5001 5076 W ReactNativeJS: - Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices
05-04 19:01:21.343 5001 5076 W ReactNativeJS: - If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device
05-04 19:01:21.343 5001 5076 W ReactNativeJS: - If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081
05-04 19:01:21.343 5001 5076 W ReactNativeJS:
05-04 19:01:21.343 5001 5076 W ReactNativeJS: URL: 10.0.2.2:8081
05-04 19:01:21.343 5001 5076 W ReactNativeJS:
05-04 19:01:21.343 5001 5076 W ReactNativeJS: Error: null
05-04 19:01:28.578 5227 5273 I ReactNativeJS: Bridgeless mode is enabled
05-04 19:01:29.052 5227 5273 E ReactNativeJS: TypeError: _result.isRoot is not a function (it is undefined)
05-04 19:01:29.060 5227 5273 I ReactNativeJS: Running "main" with {"rootTag":11,"initialProps":{},"fabric":true}
05-04 19:01:45.724 5362 5420 I ReactNativeJS: Bridgeless mode is enabled
05-04 19:01:46.172 5362 5420 E ReactNativeJS: TypeError: _result.isRoot is not a function (it is undefined)
05-04 19:01:46.183 5362 5420 I ReactNativeJS: Running "main" with {"rootTag":11,"initialProps":{},"fabric":true}
05-04 19:05:04.724 5883 5928 I ReactNativeJS: Bridgeless mode is enabled
05-04 19:05:05.183 5883 5928 E ReactNativeJS: TypeError: _result.isRoot is not a function (it is undefined)
05-04 19:05:05.192 5883 5928 I ReactNativeJS: Running "main" with {"rootTag":11,"initialProps":{},"fabric":true}
Or if you are using Android Studio, open the folder expo-arktype-repro/android (MUST DO THIS AFTER npx expo prebuild) in Android Studio. Then, open logcat in bottom left of the ui.
Let me know if you need further assistance.
I do get Cannot convert undefined value to object on iOS w/ Expo - assume this might be something similar
@tobimori any solutions
I have this error too :( can't use ArkType for now
For me, it is the type.or calls that causing the crash on start
I haven't really put this through its paces yet, but this seems similar to #1027. I've at least been able to get through the startup error when booting react-native through the following patch:
diff --git a/ark/schema/shared/disjoint.ts b/ark/schema/shared/disjoint.ts
index 6973ad5c5a..df76456419 100644
--- a/ark/schema/shared/disjoint.ts
+++ b/ark/schema/shared/disjoint.ts
@@ -101,11 +101,17 @@
}
withPrefixKey(key: PropertyKey, kind: Prop.Kind): Disjoint {
- return this.map(entry => ({
+ const result = this.map(entry => ({
...entry,
path: [key, ...entry.path],
optional: entry.optional || kind === "optional"
})) as Disjoint
+ if (!(result instanceof Disjoint)) return new Disjoint(...result)
+
+ return result
}
toNeverIfDisjoint(): BaseRoot {