bun
bun copied to clipboard
adapter error in Axios
adapter is not a function. (In 'adapter(config)', 'adapter' is undefined)
I'm getting this error when i tries to run axios function
Thanks for reporting @faizalom, could you provide a quick code sample so we can reproduce?
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
bump
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
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
I just ran into the same issue independently
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.