Cannot read property 'fetch' of undefined in React Native

Hi, everyone!

I’m new to TensorFlow and I’m trying to use it in a CLI React Native application. I’ve tried both coco-ssd and mobilenet and both give the same error on load(). I provided some code below.

I’m not sure what I could do at this point, I’ve been stuck with this for 2 days. Any help is appreciated, thanks!

import React from "react";
import { useState, useEffect } from "react";
import * as cocoSsd from "@tensorflow-models/coco-ssd";
import * as tf from "@tensorflow/tfjs";

const App = () => {
    const [model, setModel] = useState<cocoSsd.ObjectDetection>()

    const loadModel = async () => {
        try {
            const model = await cocoSsd.load();
            setModel(model);
            console.log("model loaded");
        } catch (err) {
            console.log(err);
            console.log("failed to load model");
        }
    }

    useEffect(() => {
        tf.ready().then(() => {
            loadModel();
        });
    }, []);
}

from package.json:

 "@tensorflow-models/coco-ssd": "^2.2.2",
 "@tensorflow/tfjs": "^4.2.0",

any updates on this ??

i’m stuck at the same point

I managed to get it working with a combination of older versions. To do so, I cloned the following repository and used one of the examples: tfjs-examples/react-native at master · tensorflow/tfjs-examples · GitHub

It’s not the best option, as I’m sure I’ll have a lot of trouble with new libraries, but it’s the only thing that worked so far.

hi can you tell me which older versions you used?