bun icon indicating copy to clipboard operation
bun copied to clipboard

Implement Node's "dns" module

Open bagusprabangkoro opened this issue 3 years ago • 10 comments

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()

bagusprabangkoro avatar Jul 06 '22 19:07 bagusprabangkoro

Node's dns module hasn't been implemented yet. Updating this issue to track that

Jarred-Sumner avatar Jul 07 '22 00:07 Jarred-Sumner

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.

dylang avatar Jul 11 '22 21:07 dylang

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%

mve avatar Jul 12 '22 20:07 mve

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

112RG avatar Jul 12 '22 20:07 112RG

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 avatar Jul 16 '22 10:07 sondreb

@sondreb https://github.com/erfanium/atlas_sdk should work if you are using Atlas

erfanium avatar Jul 27 '22 05:07 erfanium

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.

SheetJSDev avatar Jul 31 '22 02:07 SheetJSDev

For informational purposes: the pg Postgres module is blocked by this.

spiffytech avatar Sep 21 '22 14:09 spiffytech

this issue still persists with v0.3.0

TechFun4 avatar Dec 09 '22 19:12 TechFun4

Jarred has shown interest in implementing this for v0.4.0, as it's required for Vite support.

spiffytech avatar Dec 09 '22 19:12 spiffytech

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

Jarred-Sumner avatar Jan 10 '23 02:01 Jarred-Sumner

Does this now mean we'll get Vite support? 👀

ThatOneCalculator avatar Jan 10 '23 07:01 ThatOneCalculator

Does this now mean we'll get Vite support? 👀

Almost

ThatOneBro avatar Jan 10 '23 07:01 ThatOneBro