Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
net polyfill
✓ import {} from '@jchoi2x/cf-mongodb-polyfills/net'; // via alias in wrangler.toml
✗ import { net } from 'cf-mongodb-polyfills';
Not imported directly; used via module alias. The alias maps 'net' to this package's net module.
tls polyfill
✓ // aliased in wrangler.toml: 'tls' = '@jchoi2x/cf-mongodb-polyfills/tls'
✗ import { tls } from 'cf-mongodb-polyfills';
Similar to net; aliased, not imported directly.
dns polyfill
✓ // aliased in wrangler.toml: 'dns' = '@jchoi2x/cf-mongodb-polyfills/dns'
✗ import { dns } from 'cf-mongodb-polyfills';
Aliased as well.
MongoClient (using polyfills)
✓ import { MongoClient } from 'mongodb';
MongoClient usage remains unchanged; polyfills work via aliasing.
Demonstrates wrangler.toml aliasing and using MongoClient in a Cloudflare Worker with the polyfill.
// wrangler.toml
[alias]
"net" = "@jchoi2x/cf-mongodb-polyfills/net"
"dns" = "@jchoi2x/cf-mongodb-polyfills/dns"
"tls" = "@jchoi2x/cf-mongodb-polyfills/tls"
// src/index.ts
import { MongoClient } from 'mongodb';
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const uri = process.env.MONGODB_URI ?? 'mongodb+srv://user:pass@cluster.mongodb.net/myDB?retryWrites=true&w=majority';
const client = new MongoClient(uri);
await client.connect();
const db = client.db('test');
const users = await db.collection('users').find({}).limit(10).toArray();
await client.close();
return Response.json({ users });
},
} satisfies ExportedHandler<Env>;
Errors
Common errors & fixes
Error: The module "net" cannot be resolved. Did you mean to enable the nodejs_compat compatibility flag?
Missing wrangler.toml alias for 'net'.
fixAdd [alias] section with 'net' = '@jchoi2x/cf-mongodb-polyfills/net'
TypeError: net.createConnection is not a function
Node.js compatibility flags enabled but no alias pointing to polyfill.
fixAdd the alias in wrangler.toml instead of relying on nodejs_compat alone.
Cannot find module '@jchoi2x/cf-mongodb-polyfills/net'
Package not installed or alias path typo (missing '@jchoi2x/' prefix).
fixRun 'npm install cf-mongodb-polyfills' and ensure alias uses '@jchoi2x/cf-mongodb-polyfills/net'.
Audit
Dependencies
No dependency data recorded yet.