miniflare
4.20260730.0 · 30 Jul 2026MIT57.5M / weekRepositoryHomepagenpmAtom feed
3.20250718.3 is the newest release of 3.x.
In short
4 new3 fixed
Release note
Minor Changes
Pass
Miniflareinstance as argument to custom service binding handlersThis change adds a new
Miniflare-typed parameter to function-valued service binding handlers. This provides easy access to the correct bindings when re-using service functions across instances.import assert from "node:assert"; import { Miniflare, Response } from "miniflare"; const mf = new Miniflare({ serviceBindings: { SERVICE(request, instance) { assert(instance === mf); return new Response(); }, }, });Allow
URLs to be passed inhyperdrivesPreviously, the
hyperdrivesoption only acceptedstrings as connection strings. This change allowsURLobjects to be passed too.Add support for custom root paths
Miniflare has lots of file-path-valued options (e.g.
scriptPath,kvPersist,textBlobBindings). Previously, these were always resolved relative to the current working directory before being used. This change adds a newrootPathshared, and per-worker option for customising this behaviour. Instead of resolving relative to the current working directory, Miniflare will now resolve path-valued options relative to the closestrootPathoption. Paths are still resolved relative to the current working directory if norootPaths are defined. Worker-levelrootPaths are themselves resolved relative to the sharedrootPathif defined.import { Miniflare } from "miniflare"; const mf1 = new Miniflare({ scriptPath: "index.mjs", }); const mf2 = new Miniflare({ rootPath: "a/b", scriptPath: "c/index.mjs", }); const mf3 = new Miniflare({ rootPath: "/a/b", workers: [ { name: "1", rootPath: "c", scriptPath: "index.mjs", }, { name: "2", scriptPath: "index.mjs", }, ], });Allow easy binding to current worker
Previously, if you wanted to create a service binding to the current Worker, you'd need to know the Worker's name. This is usually possible, but can get tricky when dealing with many Workers. This change adds a new
kCurrentWorkersymbol that can be used instead of a Worker name inserviceBindings.kCurrentWorkeralways points to the Worker with the binding.import { kCurrentWorker, Miniflare } from "miniflare"; const mf = new Miniflare({ serviceBindings: { SELF: kCurrentWorker, }, modules: true, script: `export default { fetch(request, env, ctx) { const { pathname } = new URL(request.url); if (pathname === "/recurse") { return env.SELF.fetch("http://placeholder"); } return new Response("body"); } }`, }); const response = await mf.dispatchFetch("http://placeholder/recurse"); console.log(await response.text()); // body
Patch Changes
Allow relative
scriptPath/modulesRoots to break out of current working directoryPreviously, Miniflare would resolve relative
scriptPaths againstmoduleRootmultiple times resulting in incorrect paths and module names. This would lead tocan't use ".." to break out of starting directoryworkerderrors. This change ensures Miniflare usesscriptPathas is, and only resolves it relative tomodulesRootwhen computing module names. Note this bug didn't affect service workers. This allows you to reference a modulesscriptPathoutside the working directory with something like:const mf = new Miniflare({ modules: true, modulesRoot: "..", scriptPath: "../worker.mjs", });Fixes #4721
Return non-WebSocket responses for failed WebSocket upgrading
fetch()esPreviously, Miniflare's
fetch()would throw an error if theUpgrade: websocketheader was set, and a non-WebSocket response was returned from the origin. This change ensures the non-WebSocket response is returned fromfetch()instead, withwebSocketset tonull. This allows the caller to handle the response as they see fit.Ensure
MiniflareOptions,WorkerOptions, andSharedOptionstypes are correctMiniflare uses Zod for validating options. Previously, Miniflare inferred
*Optionsfrom the output types of its Zod schemas, rather than the input types. In most cases, these were the same. However, thehyperdrivesoption has different input/output types, preventing these from being type checked correctly.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.