bun
bun copied to clipboard
Implement Node's "dns" module
Apparently, dns module is not included on bun runtime. I got this issue when trying to use PostgreSQL (pg) package.
pg version: ^8.7.3
Error message:
error: Could not resolve: "dns". Maybe you need to "bun install"?
var dns = require('dns')
Script that I'm trying to run:
const { Pool } = require('pg')
const pool = new Pool({
user: 'test',
database: 'test'
})
const run = async () => {
const response = await DB.query('SELECT * FROM test LIMIT 10')
console.log(response.rows)
}
run()
Node's dns module hasn't been implemented yet. Updating this issue to track that
DX suggestion: Instead of Could not resolve: "dns". Maybe you need to "bun install"? could the error message for non-implemented node features be something like:
Bun has not yet implemented node's dns package. You will need to disable code that uses this for now. Follow https://github.com/oven-sh/bun/issues/288 for progress on this feature.
Same thing for mongodb:
error: Could not resolve: "dns". Maybe you need to "bun install"?
const dns = require("dns");
^
.../node_modules/mongodb/lib/connection_string.js:4:21 249%
This is happening because bun is yet to implement that part of the Node.JS API. This is not because you need to install them. These are modules supplied by NodeJS itself like the FS module. You can see here https://github.com/oven-sh/bun/tree/main/src/bun.js/node the current modules of Node.JS that Bun supports
Mongoose requires DNS as well, so unable to use MongoDB from Bun. I don't know if there are other options to communicate with MongoDB from Bun?
@sondreb https://github.com/erfanium/atlas_sdk should work if you are using Atlas
PR 929 implements a DoH fallback against cloudflare.
Note that after the patch, modules are still blocked by other issues like tls / net#Socket / RegExp lookbehind.
For informational purposes: the pg Postgres module is blocked by this.
this issue still persists with v0.3.0
Jarred has shown interest in implementing this for v0.4.0, as it's required for Vite support.
A simple version of dns.lookup and dns.resolve is now available in the canary build of Bun - https://github.com/oven-sh/bun/pull/1691
bun upgrade --canary
The issue for tracking the implementation progress of node:dns is here: https://github.com/oven-sh/bun/issues/1744
Does this now mean we'll get Vite support? 👀
Does this now mean we'll get Vite support? 👀
Almost