React & Clarifai:未捕获的 ReferenceError:流程未定义

2023-12-20

我正在使用 Clarifai API 中的人脸检测模型构建一个 React 应用程序。当我import Clarifai from "clarifai",VS Code 提示我此警告:

Could not find a declaration file for module 'clarifai'. '.../face-recognition/node_modules/clarifai/dist/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/clarifai` if it exists or add a new declaration (.d.ts) file containing `declare module 'clarifai';`ts(7016)

我尝试了建议的解决方案,但只收到错误:

npm i --save-dev @types/clarifai
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fclarifai - Not found
npm ERR! 404
npm ERR! 404  '@types/clarifai@*' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

当我运行 npm start 时,出现空白屏幕,检查控制台并给出以下错误:

Uncaught ReferenceError: process is not defined
    _init App.js:124
    App App.js:53
    js App.js:14
    factory react refresh:6

前两个返回到安装在node_modules文件夹中的clarifai文件夹。第三个是我的“导入 Clarifai”代码。

是API客户端安装方式有问题,还是我这边有问题?

谢谢您的帮助!


这里发生了很多事情:

  • 您似乎正在使用已弃用的软件包(https://github.com/Clarifai/clarifai-javascript https://github.com/Clarifai/clarifai-javascript)。我们早在 2020 年就已弃用此包。如果您专门使用包客户端,我们建议直接使用 REST 端点。请参阅文档中的“Javascript (REST)”片段:https://docs.clarifai.com/api-guide/predict/images#via-url https://docs.clarifai.com/api-guide/predict/images#via-url
  • 你得到了process is not defined因为客户端应用程序无法访问process原生运行。如果您使用 webpack,则可以将其传递给DefinePlugin包裹 (未捕获的引用错误:进程未定义 https://stackoverflow.com/questions/30239060/uncaught-referenceerror-process-is-not-defined)。还有其他方式可以访问process客户端,我邀请你谷歌一下

让我知道这是否有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React & Clarifai:未捕获的 ReferenceError:流程未定义 的相关文章

随机推荐