Getting an error while loading the model

I am trying to make an object detection application using tf.js with React Native. I’m trying to load the model after calling the tf.ready() function and I’m getting an error. I tried locally and using the cocoSsd package.

import React, { useState, useEffect } from "react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import * as tf from "@tensorflow/tfjs";
import "@tensorflow/tfjs-react-native";
import { bundleResourceIO } from "@tensorflow/tfjs-react-native";
import * as cocoSsd from '@tensorflow-models/coco-ssd';

const modelJson = require('./assets/model.json')
const modelWeight1 = require('./assets/group1-shard1of2.bin')
const modelWeight2 = require('./assets/group1-shard2of2.bin')

export default function App() {
  const [isTfReady, setIsTfReady] = useState(false);
  const [model, setModel] = useState();

  useEffect(() => {
    (async () => {
      // Calling setBackend() method
      // tf.setBackend("webgl");

      // Calling ready() method and
      // Printing output
      await tf
        .then((a) => {
        .catch((e) => console.log("hataa", e));

      const model = await tf.loadGraphModel(bundleResourceIO(modelJson, [modelWeight1, modelWeight2]))

      const model2 = await cocoSsd.load();

  }, []);
  console.log("isTfReady :", isTfReady);
  //console.log("model :", model);

  // if (!model) {
  //   return (<View style={styles.container}><Text>No model</Text></View>)
  // }

  return (
    <View style={styles.container}>
      <Text>Test app!</Text>
      <StatusBar style="auto" />

I’m getting this error ;

 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not a function
TypeError: undefined is not a function
    at isTypedArray (
    at inferShape (
    at tensor (
    at decodeWeights (
    at anonymous (
    at anonymous (
    at tryCallOne (/Users/kudo/01_Work/Repos/expo/expo/android/versioned-react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/5a4n485h/arm64-v8a/lib/InternalBytecode/Intern
    at anonymous (/Users/kudo/01_Work/Repos/expo/expo/android/versioned-react-native/ReactAndroid/hermes-engine/.cxx/MinSizeRel/5a4n485h/arm64-v8a/lib/InternalBytecode/Interna
    at apply (native)
    at anonymous (
    at _callTimer (
    at _callReactNativeMicrotasksPass (
    at callReactNativeMicrotasks (
    at __callReactNativeMicrotasks (
    at anonymous (
    at __guard (
    at flushedQueue (
    at callFunctionReturnFlushedQueue (

I’ve got the same problem using expo. I tried using different versions of tf or cocoSsd but nothing.
The cocoSsd.load() is not working…

On some forum i read that could be tensorflow not loading properly but i don’t really know what’s the problem here.

I solved it. There is a problem with package versions. My package.json file looks like this:

  "name": "demo-js",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  "dependencies": {
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@tensorflow-models/coco-ssd": "^2.2.2",
    "@tensorflow/tfjs": "3.18.0",
    "@tensorflow/tfjs-react-native": "^0.8.0",
    "@types/react-native-canvas": "^0.1.9",
    "expo": "~46.0.2",
    "expo-camera": "^12.3.0",
    "expo-gl": "^11.4.0",
    "expo-gl-cpp": "^11.4.0",
    "expo-status-bar": "~1.4.4",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native": "0.69.3",
    "react-native-canvas": "^0.1.38",
    "react-native-fs": "2.14.1",
    "react-native-webview": "^11.26.1"
  "devDependencies": {
    "@babel/core": "^7.9.0"
  "private": true

But I ran into another problem. The camera does not work fluently and sends an alert.

tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead

Which version packages did you change ?, In my case I have higher version than you do right now