-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What version of Bun is running?
0.6.9
What platform is your computer?
Darwin 22.5.0 arm64 arm
What steps can reproduce the bug?
This is actually quite easy to reproduce. Run the following lines in your shell and you'll see the error:
mkdir bunVsAxios && cd bunVsAxios
bun init -y
bun install resend
cat <<EOT > index.ts
import resend from "resend";
const client = new resend.Resend("re_xxx");
await client.sendEmail({
from: "[email protected]",
to: "[email protected]",
subject: "Hello World!",
text: "Hello World!",
});
EOT
bun run index.ts
It's a fresh bun project with resend-node installed, which uses axios internally. A simple API call triggers the error.
Here's the code for index.ts itself in case you don't want to copy&paste the script above:
import resend from "resend";
const client = new resend.Resend("re_xxx");
await client.sendEmail({
from: "[email protected]",
to: "[email protected]",
subject: "Hello World!",
text: "Hello World!",
});
What is the expected behavior?
Request is sent with axios without adapter errors.
What do you see instead?
error: Adapter 'http' is not available in the build
at /playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:2444:12
at /playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:2499:18
at request (/playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:2859:16)
at httpMethod (/playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:2898:13)
at wrap (/playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:6:11)
at /playground/bunVsAxios/node_modules/resend/build/src/resend.js:66:29
at /playground/bunVsAxios/node_modules/resend/build/src/resend.js:8:8
at /playground/bunVsAxiosx/node_modules/resend/build/src/resend.js:4:11
at /playground/bunVsAxios/node_modules/resend/build/src/resend.js:122:39
at /playground/bunVsAxios/node_modules/resend/build/src/resend.js:8:8
at /playground/bunVsAxios/node_modules/resend/build/src/resend.js:4:11
at /playground/bunVsAxios/index.ts:5:18
Additional information
When installing and using axios directly, everything works as expected, and bun's module resolution logic apparently resolves to the correct axios export.
However, when installing a library which uses axios internally (i.e. resend-node in my case), the request fails with the following error:
Adapter 'http' is not available in the build
That was weird to me initially, because resolution was fixed some time ago, specifically mentioning axios.
However, I found that bun is actually resolving to the browser version of axios, as it can be seen in the stack trace:
/playground/bunVsAxios/node_modules/axios/dist/browser/axios.cjs:2444:12
However, I'd expect to see bun resolving to the node version of axios instead.