cloudflare / miniflare

🔥 Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare.
https://miniflare.dev
MIT License
3.78k stars 205 forks source link

Multiple nodejs_compat packages missing (`crypto`, `path`, etc) #756

Closed hansottowirtz closed 9 months ago

hansottowirtz commented 9 months ago

When using nodejs_compat in Miniflare 2, only the following modules are available: assert, async_hooks, buffer, events, util

These ones are missing: crypto, diagnostics_channel, path, process, stream (and stream/promises, stream/consumers), string_decoder.

I'm willing to add these, but as this package is almost deprecated, would you be open for a PR? As we're using globals we can't migrate to Miniflare 3 yet.

mrbbot commented 9 months ago

Hey! 👋 Yep, we'd be open to a PR, but as you point out this package is pretty-much deprecated. What are you using globals for? It's possible Miniflare 3 provides a mechanism that would help with your use case. 🙂

hansottowirtz commented 9 months ago

I'm creating a Knex client in Node that connects to our local database and then passing it to Miniflare:

    globals: {
      _local_createGlobalKnexClient: createKnexClient,
      _local_getPostgresClient: () => postgresNode(dbConnectionString),
    }

However I think this would be fixed once Hyperdrive support (with local databases support) is added to Miniflare 3.

mrbbot commented 9 months ago

Cool! Miniflare 3 does support Hyperdrive now, looks like this wasn't added to the API documentation though.

const mf = new Miniflare({
  hyperdrives: {
    DB: "postgresql://user:password@localhost:5432/database"
  }
});
mrbbot commented 9 months ago

Hey again! 👋 I'm going to close this issue since it looks like you've been able to switch to Miniflare 3, and we're getting very close to deprecating Miniflare 2 now that https://github.com/cloudflare/workers-sdk/pull/4795 is up. 👍