|
2 | 2 | order: 3 |
3 | 3 | --- |
4 | 4 |
|
| 5 | +# ⬆️ Migrating from Version 2 |
| 6 | + |
| 7 | +Refer to |
| 8 | +[the Miniflare and workerd blog post](https://blog.cloudflare.com/miniflare-and-workerd/) |
| 9 | +for the Miniflare v3 announcement. |
| 10 | + |
| 11 | +## Missing Features |
| 12 | + |
| 13 | +Several features from Miniflare v2 are not supported in Miniflare v3's initial |
| 14 | +release. However, they are on the roadmap, and will be added soon: |
| 15 | + |
| 16 | +- Step-through debugging |
| 17 | +- Automatically triggering scheduled events via CRON schedules, or manually |
| 18 | + triggering them via `/.mf/scheduled` or `/cdn-cgi/mf/scheduled` (manually |
| 19 | + triggering events is supported via the `--test-scheduled` Wrangler flag and |
| 20 | + visiting `/__scheduled`) |
| 21 | +- Starting an HTTPS server |
| 22 | + |
| 23 | +## CLI Changes |
| 24 | + |
| 25 | +Miniflare v3 no longer includes a standalone CLI. To get the same functionality, |
| 26 | +you will need to switch over to using |
| 27 | +[Wrangler](https://developers.cloudflare.com/workers/wrangler/). Wrangler v3 |
| 28 | +uses Miniflare v3 by default. To use Wrangler, run: |
| 29 | + |
| 30 | +```sh |
| 31 | +$ npx wrangler@3 dev |
| 32 | +``` |
| 33 | + |
| 34 | +If there are features from the Miniflare CLI you would like to see in Wrangler, |
| 35 | +please open an issue on |
| 36 | +[GitHub](https://github.com/cloudflare/workers-sdk/issues/new/choose). |
| 37 | + |
| 38 | +## API Changes |
| 39 | + |
| 40 | +We have tried to keep Miniflare v3’s API close to Miniflare v2 where possible, |
| 41 | +but many options and methods have been removed or changed with the switch to the |
| 42 | +open-source `workerd` runtime. See the |
| 43 | +[GitHub `README` for the new API docs](https://github.com/cloudflare/miniflare/blob/tre/packages/miniflare/README.md). |
| 44 | + |
| 45 | +### Changed Options |
| 46 | + |
| 47 | +#### `bindings` |
| 48 | + |
| 49 | +Values passed to the `bindings` option must now be JSON-serialisable. Consider |
| 50 | +using the `serviceBindings` option if you need to bind custom functions. |
| 51 | + |
| 52 | +### Removed Options |
| 53 | + |
| 54 | +#### `wranglerConfigPath` and `wranglerConfigEnv` |
| 55 | + |
| 56 | +Miniflare no longer handles Wrangler’s configuration. To programmatically start |
| 57 | +up a Worker with Wrangler configuration, use the |
| 58 | +[`unstable_dev()`](https://developers.cloudflare.com/workers/wrangler/api/#unstable_dev) |
| 59 | +API. |
| 60 | + |
| 61 | +#### `packagePath` |
| 62 | + |
| 63 | +Specify your script using the `scriptPath` option instead. |
| 64 | + |
| 65 | +#### `upstream` |
| 66 | + |
| 67 | +Always pass the full upstream URL when calling `dispatchFetch()`. |
| 68 | + |
| 69 | +#### `watch` |
| 70 | + |
| 71 | +Miniflare’s API is primarily intended for testing use cases, where file watching |
| 72 | +isn’t too important. This option was here to enable Miniflare’s CLI which has |
| 73 | +now been removed. If you need to watch files, consider using a separate file |
| 74 | +watcher and calling `setOptions()` with your original config on change. |
| 75 | + |
| 76 | +#### `logUnhandledRejections` |
| 77 | + |
| 78 | +Unhandled rejections can be handled in Workers with |
| 79 | +[`addEventListener("unhandledrejection")`](https://community.cloudflare.com/t/2021-10-21-workers-runtime-release-notes/318571) |
| 80 | + |
| 81 | +#### `globalAsyncIO`, `globalTimers`, `globalRandom`, and `inaccurateCpu` |
| 82 | + |
| 83 | +These options are not supported by |
| 84 | +[`workerd`](https://github.com/cloudflare/workerd), the open source Cloudflare |
| 85 | +Workers runtime, and so can't be supported in Miniflare. |
| 86 | + |
| 87 | +#### `actualTime` |
| 88 | + |
| 89 | +Miniflare will always return the current time. |
| 90 | + |
| 91 | +#### `https`, `httpsKey`, `httpsKeyPath`, `httpsCert`, `httpsCertPath`, `httpsPfx`, `httpsPfxPath`, and `httpsPassphrase` |
| 92 | + |
| 93 | +Miniflare does not currently support starting HTTPS servers. These options may |
| 94 | +be added back in a future release. |
| 95 | + |
| 96 | +#### `metaProvider` |
| 97 | + |
| 98 | +The `cf` object and `X-Forwarded-Proto`/`X-Real-IP` headers can be specified |
| 99 | +when calling `dispatchFetch()` instead |
| 100 | + |
| 101 | +#### `cFetch` |
| 102 | + |
| 103 | +Renamed to `cf`. |
| 104 | + |
| 105 | +#### `crons` |
| 106 | + |
| 107 | +This is not currently supported by |
| 108 | +[`workerd`](https://github.com/cloudflare/workerd), the open source Cloudflare |
| 109 | +Workers runtime, but will be in a future release. |
| 110 | + |
| 111 | +#### `durableObjectAlarms` |
| 112 | + |
| 113 | +Durable Object alarms are always enabled in Miniflare v3. |
| 114 | + |
| 115 | +#### `globals` |
| 116 | + |
| 117 | +`globals` is not supported by |
| 118 | +[`workerd`](https://github.com/cloudflare/workerd), the open source Cloudflare |
| 119 | +Workers runtime. |
| 120 | + |
| 121 | +#### `mounts` |
| 122 | + |
| 123 | +Miniflare v3 does not have the concept of parent/child Workers. Instead, all |
| 124 | +Workers are at the same level. The same functionality can be achieved using the |
| 125 | +`workers` option. Note some options are always top-level, and some options are |
| 126 | +per-Worker. |
| 127 | + |
| 128 | +### Changed Methods |
| 129 | + |
| 130 | +#### `setOptions()` |
| 131 | + |
| 132 | +Calling `setOptions()` now requires a full configuration object, not a partial |
| 133 | +patch. |
| 134 | + |
| 135 | +### Removed Methods |
| 136 | + |
| 137 | +#### `reload()` |
| 138 | + |
| 139 | +Call `setOptions()` with the original configuration object instead. |
| 140 | + |
| 141 | +#### `getMount()` |
| 142 | + |
| 143 | +Miniflare v3 does not have the concept of parent/child Workers. Instead, all |
| 144 | +Workers are at the same level. Refer to the |
| 145 | +[`3.0.0-next.1` release notes](https://github.com/cloudflare/miniflare/releases/tag/v3.0.0-next.1) |
| 146 | +for an example multi-Worker configuration. |
| 147 | + |
| 148 | +#### `createServer()` and `startServer()` |
| 149 | + |
| 150 | +These methods are now redundant. Miniflare v3 always starts an HTTP server. |
| 151 | + |
| 152 | +#### `startScheduled()` and `dispatchScheduled()` |
| 153 | + |
| 154 | +[`workerd`](https://github.com/cloudflare/workerd) does not support triggering |
| 155 | +scheduled events yet, but will in an upcoming release. |
| 156 | + |
| 157 | +#### `dispatchQueue()` |
| 158 | + |
| 159 | +Use the `queue()` method on |
| 160 | +[service bindings](https://developers.cloudflare.com/workers/platform/bindings/about-service-bindings/) |
| 161 | +or |
| 162 | +[queue producer bindings](https://developers.cloudflare.com/queues/platform/configuration/#producer). |
| 163 | + |
| 164 | +#### `Response#waitUntil()` |
| 165 | + |
| 166 | +[`workerd`](https://github.com/cloudflare/workerd) does not support waiting for |
| 167 | +all `waitUntil()`ed promises yet. |
| 168 | + |
| 169 | +#### `getGlobalScope()`, `getBindings()`, `getModuleExports()`, `getKVNamespace()`, `getR2Bucket()`, `getCaches()`, and `getDurableObjectNamespace()` |
| 170 | + |
| 171 | +These methods returned objects from inside the Workers sandbox. Since Miniflare |
| 172 | +now uses [`workerd`](https://github.com/cloudflare/workerd), which runs in a |
| 173 | +different process, these methods can no longer be supported. |
| 174 | + |
5 | 175 | # ⬆️ Migrating from Version 1 |
6 | 176 |
|
7 | 177 | Miniflare 2 includes [breaking changes](/get-started/changelog#_2-0-0). This |
|
0 commit comments