简体   繁体   中英

Im getting this error trying to use the clarifai api, how can i fix it?

im using the clarifai face recognition Api and getting an error on my console saying: "TypeError: axios.post is not a function". anyone knows how do I solve it?

  • i dont use Axios in my code, but i think the API uses it. thanks控制台上的错误

I tried installing Axios and clarifai again and it did nothing

Background: The issue you are facing is due to the dependency of Clarifai JS on axios for requests. Throughout the development of the Clarifai, the library has accepted multiple versions of axios but haven't really configured compatibility on these versions. Ex. Clarifai is familiar with axios v1.1.2 but there is no compatibility for it to work in a good condition and perform well with the library.

To solve this issue:

  1. In your package.json file, update "axios" under "dependencies" to "0.27.2" (The compatible version as of now).
  2. Add an "overrides" section and include the code below (Overrides Section).
  3. Reinstall your node_modules folder (run 'npm install')

(in 'package.json')

"dependencies": {
...
"axios": "0.27.2",
"clarifai": "^2.9.1",
...
},
"overrides": {
"clarifai": {
"axios": "$axios"
}
},
...

what package are you using? clarifai-javascript has been deprecated months ago at this point. You can still use the NodeJS gRPC package: https://www.npmjs.com/package/clarifai-nodejs-grpc or directly query the REST API: https://docs.clarifai.com/api-guide/predict/images/ (see "Javascript (REST)" snippets throughout the docs)

Thanks, @Ahmad Yousef AlOlabi Your solution worked for me! I added

"axios": "0.27.2",

in the dependencies, then I run the following:

npm install 

npm start

Happy coding @Ron reuter,

Add the line below to your package.json in the dependencies:

"axios": "0.27.2"

then run the following:

npm install 

npm start

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM