如何在 react-native 中解决这个错误?
<块引用>'可能的未处理承诺拒绝(id:0)'
每次使用 const net = await facemesh.load()
时都会出现此错误。
[TypeError: undefined is not an object (evaluating 'environment_1.env().platform.fetch')]
// TENSORFLOW DEPENDENCIES
import * as tf from '@tensorflow/tfjs';
import * as facemesh from '@tensorflow-models/facemesh';
import { drawMesh } from './src/utilities';
// LOAD FACemash
const runFacemesh = async () => {
const net = await facemesh.load();
//{input:{width:640,height:480},scale:0.8});
// setInterval(()=>{
// detect(net);
// },100)
};
// //Detect function
// const detect = async (net) => {
// if(typeof cameraRef.current !== "undefined" && cameraRef.current !== null){
// // get video properties
// const video = cameraRef.current.video;
// const videoWidth = cameraRef.current.video.videoWidth;
// const videoHeight = cameraRef.current.video.videoHeight;
// // set video width
// cameraRef.current.video.width = videoWidth;
// cameraRef.current.video.height = videoHeight;
// //set canvas width
// canvasRef.current.width = videoWidth;
// canvasRef.current.height = videoHeight;
// // make detection
// const face = await net.estimateFaces(video);
// console.log(face);
// //get canvas context from drawing
// const ctx = canvasRef.current.getContext("2d");
// drawMesh(face,ctx);
// }
// }
runFacemesh()
答案 0 :(得分:0)
如果添加 .catch()
,则不会出现此问题。然后你可以检查 net 是否有错误并决定你是否应该更进一步。
const net = await facemesh.load().catch((err) => err);
if (net instanceof Error) {
return;
}