⬆️ Migrating from Version 2
Miniflare v3 now uses workerd
↗, the
open-source Cloudflare Workers runtime. This is the same runtime that's deployed
on Cloudflare's network, giving bug-for-bug compatibility and practically
eliminating behavior mismatches. Refer to the
Miniflare v3 ↗ and
Wrangler v3 announcements ↗ for more
information.
Miniflare v3 no longer includes a standalone CLI. To get the same functionality, you will need to switch over to Wrangler. Wrangler v3 uses Miniflare v3 by default. To start a local development server, run:
If there are features from the Miniflare CLI you would like to see in Wrangler, please open an issue on GitHub ↗.
We have tried to keep Miniflare v3's API close to Miniflare v2 where possible,
but many options and methods have been removed or changed with the switch to the
open-source workerd
runtime. See the Getting Started guide for the new API docs
-
kvNamespaces/r2Buckets/d1Databases
- In addition to
string[]
s, these options now acceptRecord<string, string>
s, mapping binding names to namespace IDs/bucket names/database IDs. This means multiple Workers can bind to the same namespace/bucket/database under different names.
- In addition to
-
queueBindings
- Renamed to
queueProducers
. This either accepts aRecord<string, string>
mapping binding names to queue names, or astring[]
of binding names to queues of the same name.
- Renamed to
-
queueConsumers
-
Either accepts a
Record<string, QueueConsumerOptions>
mapping queue names to consumer options, or astring[]
of queue names to consume with default options.QueueConsumerOptions
has the following type:
-
-
cfFetch
- Renamed to
cf
. Either accepts aboolean
,string
(as before), or an object to use a thecf
object for incoming requests.
- Renamed to
-
wranglerConfigPath/wranglerConfigEnv
- Miniflare no longer handles Wrangler's configuration. To programmatically
start up a Worker based on Wrangler configuration, use the
unstable_dev()
API.
- Miniflare no longer handles Wrangler's configuration. To programmatically
start up a Worker based on Wrangler configuration, use the
-
packagePath
- Miniflare no longer loads script paths from
package.json
files. Use thescriptPath
option to specify your script instead.
- Miniflare no longer loads script paths from
-
watch
- Miniflare's API is primarily intended for testing use cases, where file
watching isn't usually required. This option was here to enable Miniflare's
CLI which has now been removed. If you need to watch files, consider using a
separate file watcher like
fs.watch()
↗ orchokidar
↗, and callingsetOptions()
with your original configuration on change.
- Miniflare's API is primarily intended for testing use cases, where file
watching isn't usually required. This option was here to enable Miniflare's
CLI which has now been removed. If you need to watch files, consider using a
separate file watcher like
-
logUnhandledRejections
- Unhandled rejections can be handled in Workers with
addEventListener("unhandledrejection")
↗.
- Unhandled rejections can be handled in Workers with
-
globals
- Injecting arbitrary globals is not supported by
workerd
↗. If you're using a service worker,bindings
will be injected as globals, but these must be JSON-serialisable.
- Injecting arbitrary globals is not supported by
-
https/httpsKey(Path)/httpsCert(Path)/httpsPfx(Path)/httpsPassphrase
- Miniflare does not support starting HTTPS servers yet. These options may be added back in a future release.
-
crons
workerd
↗ does not support triggering scheduled events yet. This option may be added back in a future release.
-
mounts
-
Miniflare no longer has the concept of parent and child Workers. Instead, all Workers can be defined at the same level, using the new
workers
option. Here's an example that uses a service binding to increment a value in a shared KV namespace:
-
-
metaProvider
- The
cf
object andX-Forwarded-Proto
/X-Real-IP
headers can be specified when callingdispatchFetch()
instead. A defaultcf
object can be specified using the newcf
option too.
- The
-
durableObjectAlarms
- Miniflare now always enables Durable Object alarms.
-
globalAsyncIO/globalTimers/globalRandom
workerd
↗ cannot support these options without fundamental changes.
-
actualTime
- Miniflare now always returns the current time.
-
inaccurateCpu
- Set the
inspectorPort: 9229
option to enable the V8 inspector. Visitchrome://inspect
in Google Chrome to open DevTools and perform CPU profiling.
- Set the
setOptions()
- Miniflare v3 now requires a full configuration object to be passed, instead of a partial patch.
reload()
- Call
setOptions()
with the original configuration object to reload Miniflare.
- Call
createServer()/startServer()
- Miniflare now always starts a
workerd
↗ server listening on the configuredhost
andport
, so these methods are redundant.
- Miniflare now always starts a
dispatchScheduled()/startScheduled()
- The functionality of
dispatchScheduled
can now be done viagetWorker()
. For more information read the scheduled events documentation.
- The functionality of
dispatchQueue()
- Use the
queue()
method on service bindings or queue producer bindings instead.
- Use the
getGlobalScope()/getBindings()/getModuleExports()
- These methods returned objects from inside the Workers sandbox. Since
Miniflare now uses
workerd
↗, which runs in a different process, these methods can no longer be supported.
- These methods returned objects from inside the Workers sandbox. Since
Miniflare now uses
addEventListener()
/removeEventListener()
- Miniflare no longer emits
reload
events. As Miniflare no longer watches files, reloads are only triggered by initialisation orsetOptions()
calls. In these cases, it's possible to wait for the reload with eitherawait mf.ready
orawait mf.setOptions()
respectively.
- Miniflare no longer emits
Response#waitUntil()
workerd
↗ does not support waiting for allwaitUntil()
ed promises yet.
@miniflare/*
- Miniflare is now contained within a single
miniflare
package.
- Miniflare is now contained within a single