bun icon indicating copy to clipboard operation
bun copied to clipboard

adapter error in Axios

Open faizalom opened this issue 1 year ago • 5 comments

adapter is not a function. (In 'adapter(config)', 'adapter' is undefined)

I'm getting this error when i tries to run axios function

faizalom avatar Oct 19 '22 08:10 faizalom

Thanks for reporting @faizalom, could you provide a quick code sample so we can reproduce?

Electroid avatar Oct 19 '22 18:10 Electroid

Thanks for reporting @faizalom, could you provide a quick code sample so we can reproduce?

@Electroid Please check this code snippet

const axios = require('axios');

axios.post('https://swapi.dev/api/')
    .then(function (response) {
        // handle success
        console.log(response);
    })
    .catch(function (error) {
        // handle error
        console.log(error);
    });

Error which I am getting Please check this

faizalom avatar Oct 20 '22 18:10 faizalom

bump

laffed avatar Oct 24 '22 19:10 laffed

I know this is something we have to solve in time but I recommend to use the built-in fetch and also axios is one of the slowest http clients. @faizalom

xHyroM avatar Nov 03 '22 15:11 xHyroM

OpenAIApi happens to use Axios.

Here is sample code:

import { Configuration, OpenAIApi } from "openai";
import dotenv from "dotenv";

dotenv.config();

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
  model: "text-davinci-003",
  prompt: "Convert movie titles into emoji.\n\nBack to the Future: 👨👴🚗🕒 \nBatman: 🤵🦇 \nTransformers: 🚗🤖 \nStar Wars:",
  temperature: 0.8,
  max_tokens: 60,
  top_p: 1.0,
  frequency_penalty: 0.0,
  presence_penalty: 0.0,
  stop: ["\n"],
});
console.log(response.data.choices.map(c => c.text));

Node runs this without problem

$ node -v
v19.6.0
$ node index.js 
[ '🚀⭐🤴👸' ]

Bun has this adaptor issue

$ bun -v
0.5.6
$ bun index.js 
[0.01ms] ".env"
53 |     }
54 |   );
55 | 
56 |   var adapter = config.adapter || defaults.adapter;
57 | 
58 |   return adapter(config).then(function onAdapterResolution(response) {
             ^
TypeError: adapter is not a function. (In 'adapter(config)', 'adapter' is undefined)
      at dispatchRequest (/home/tlin34/workspace/gpt-playground/node_modules/axios/lib/core/dispatchRequest.js:58:9)
      at request (/home/tlin34/workspace/gpt-playground/node_modules/axios/lib/core/Axios.js:108:14)

While I agree that fetch is generally the preferred method for making HTTP requests, there are cases where it may not be suitable. For example, when dealing with a third-party API, bun may not be a viable solution

zero41120 avatar Feb 18 '23 10:02 zero41120

I just ran into the same issue independently

onionhammer avatar Mar 18 '23 15:03 onionhammer

Same issue, wanted to try the Bun, literally my first app in Bun and it disappointed me. Not really a drop-in replacement for Node, because many third party packages use axios.

mariobm avatar Mar 19 '23 19:03 mariobm