Skip to content

Commit 56021a0

Browse files
korinnehyperlint-ai[bot]penalosaemily-shenlrapoport-cf
authored andcommitted
Wrangler v4 migration guide (#18726)
* adds migration guide draft for Wrangler v4 * Fixes typos and reorders migration docs to start with v4 * Update src/content/docs/workers/wrangler/migration/update-v3-to-v4.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> * Update src/content/docs/workers/wrangler/migration/update-v3-to-v4.mdx Co-authored-by: Somhairle MacLeòid <[email protected]> * Update src/content/docs/workers/wrangler/migration/update-v3-to-v4.mdx Co-authored-by: Somhairle MacLeòid <[email protected]> * update `wrangler types` runtime type gen instructions * Remove @types/node known issue * WIP * more docs * typo * Add changelog * Apply suggestions from code review Co-authored-by: lrapoport-cf <[email protected]> Co-authored-by: emily-shen <[email protected]> * more removed deprecations * Apply suggestions from code review Co-authored-by: lrapoport-cf <[email protected]> * Update src/content/changelog/workers/2025-03-13-wrangler-v4.mdx --------- Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> Co-authored-by: Somhairle MacLeòid <[email protected]> Co-authored-by: emily-shen <[email protected]> Co-authored-by: lrapoport-cf <[email protected]>
1 parent 29bafe6 commit 56021a0

File tree

20 files changed

+266
-278
lines changed

20 files changed

+266
-278
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Use the latest JavaScript features with Wrangler CLI v4
3+
description: Wrangler v4 is available!
4+
products:
5+
- workers
6+
date: 2025-03-13T09:00:00Z
7+
---
8+
9+
import { PackageManagers } from "~/components";
10+
11+
We've released the next major version of [Wrangler](/workers/wrangler/), the CLI for Cloudflare Workers — `[email protected]`. Wrangler v4 is a major release focused on updates to underlying systems and dependencies, along with improvements to keep Wrangler commands consistent and clear.
12+
13+
You can run the following command to install it in your projects:
14+
15+
<PackageManagers pkg="wrangler@latest" />
16+
17+
Unlike previous major versions of Wrangler, which were [foundational rewrites](https://blog.cloudflare.com/wrangler-v2-beta/) and [rearchitectures](https://blog.cloudflare.com/wrangler3/) — Version 4 of Wrangler includes a much smaller set of changes. If you use Wrangler today, your workflow is very unlikely to change.
18+
19+
A [detailed migration guide](/workers/wrangler/migration/update-v3-to-v4) is available and if you find a bug or hit a roadblock when upgrading to Wrangler v4, [open an issue on the `cloudflare/workers-sdk` repository on GitHub](https://github.com/cloudflare/workers-sdk/issues/new?template=bug-template.yaml).
20+
21+
Going forward, we'll continue supporting Wrangler v3 with bug fixes and security updates until Q1 2026, and with critical security updates until Q1 2027, at which point it will be out of support.

src/content/docs/pages/framework-guides/deploy-a-hono-site.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Open your `package.json` file and update the `scripts` section:
7070
"dev:wrangler": "wrangler pages dev dist --live-reload",
7171
"dev:esbuild": "esbuild --bundle src/server.js --format=esm --watch --outfile=dist/_worker.js",
7272
"build": "esbuild --bundle src/server.js --format=esm --outfile=dist/_worker.js",
73-
"deploy": "wrangler pages publish dist"
73+
"deploy": "wrangler pages deploy dist"
7474
},
7575
```
7676

@@ -82,7 +82,7 @@ Open your `package.json` file and update the `scripts` section:
8282
"dev:wrangler": "wrangler pages dev dist --live-reload",
8383
"dev:esbuild": "esbuild --bundle src/server.ts --format=esm --watch --outfile=dist/_worker.js",
8484
"build": "esbuild --bundle src/server.ts --format=esm --outfile=dist/_worker.js",
85-
"deploy": "wrangler pages publish dist"
85+
"deploy": "wrangler pages deploy dist"
8686
},
8787
```
8888

src/content/docs/pages/functions/typescript.mdx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@ sidebar:
55
order: 8
66
---
77

8+
import { PackageManagers, Render } from "~/components";
9+
810
Pages Functions supports TypeScript. Author any files in your `/functions` directory with a `.ts` extension instead of a `.js` extension to start using TypeScript.
911

10-
To add the runtime types to your project, run:
12+
You can add runtime types and Env types by running:
1113

12-
```sh
13-
npm install --save-dev typescript @cloudflare/workers-types
14-
```
14+
<PackageManagers
15+
type="exec"
16+
pkg="wrangler"
17+
args={"types --path='./functions/types.d.ts'"}
18+
/>
1519

16-
Then configure the runtime types by creating a `functions/tsconfig.json` file:
20+
Then configure the types by creating a `functions/tsconfig.json` file:
1721

1822
```json
1923
{
2024
"compilerOptions": {
2125
"target": "esnext",
2226
"module": "esnext",
2327
"lib": ["esnext"],
24-
"types": ["@cloudflare/workers-types"]
28+
"types": ["./types.d.ts"]
2529
}
2630
}
2731
```
2832

33+
See [the `wrangler types` command docs](/workers/wrangler/commands/#types) for more details.
34+
2935
If you already have a `tsconfig.json` at the root of your project, you may wish to explicitly exclude the `/functions` directory to avoid conflicts. To exclude the `/functions` directory:
3036

3137
```json
@@ -36,7 +42,9 @@ If you already have a `tsconfig.json` at the root of your project, you may wish
3642
}
3743
```
3844

39-
Pages Functions can be typed using the `PagesFunction` type. This type accepts an `Env` parameter. To use the `env` parameter:
45+
Pages Functions can be typed using the `PagesFunction` type. This type accepts an `Env` parameter. The `Env` type should have been generated by `wrangler types` and can be found at the top of `types.d.ts`.
46+
47+
Alternatively, you can define the `Env` type manually. For example:
4048

4149
```ts
4250
interface Env {
@@ -48,3 +56,22 @@ export const onRequest: PagesFunction<Env> = async (context) => {
4856
return new Response(value);
4957
};
5058
```
59+
60+
If you are using `nodejs_compat`, make sure you have installed `@types/node` and updated your `tsconfig.json`.
61+
62+
```json
63+
{
64+
"compilerOptions": {
65+
"target": "esnext",
66+
"module": "esnext",
67+
"lib": ["esnext"],
68+
"types": ["./types.d.ts", "node"]
69+
}
70+
}
71+
```
72+
73+
:::note
74+
75+
If you were previously using `@cloudflare/workers-types` instead of the runtime types generated by `wrangler types`, you can refer to this [migration guide](/workers/languages/typescript/#migrating).
76+
77+
:::

src/content/docs/workers/configuration/multipart-upload-metadata.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ At a minimum, the `main_module` key is required to upload a Worker.
6868

6969
* [Compatibility Flags](/workers/configuration/compatibility-flags/#setting-compatibility-flags) that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a `compatibility_date`.
7070

71-
* `usage_model` <Type text="string" /> <MetaInfo text="optional" />
72-
73-
* Usage model to apply to invocations, only allowed value is `standard`.
74-
75-
7671

7772
## Additional attributes: [Workers Script Upload API](/api/resources/workers/subresources/scripts/methods/update/)
7873

src/content/docs/workers/languages/javascript/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ sidebar:
66

77
---
88

9-
## JavaScript
109

1110
The Workers platform is designed to be [JavaScript standards compliant](https://ecma-international.org/publications-and-standards/standards/ecma-262/) and web-interoperable, and supports JavaScript standards, as defined by [TC39](https://tc39.es/) (ECMAScript). Wherever possible, it uses web platform APIs, so that code can be reused across client and server, as well as across [WinterCG](https://wintercg.org/) JavaScript runtimes.
1211

src/content/docs/workers/languages/typescript/index.mdx

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,107 +8,128 @@ head:
88
content: Write Cloudflare Workers in TypeScript
99
---
1010

11-
import { TabItem, Tabs } from "~/components";
11+
import { TabItem, Tabs, PackageManagers, Render } from "~/components";
1212

13-
## TypeScript
13+
TypeScript is a first-class language on Cloudflare Workers. All APIs provided in Workers are fully typed, and type definitions are generated directly from [workerd](https://github.com/cloudflare/workerd), the open-source Workers runtime.
1414

15-
TypeScript is a first-class language on Cloudflare Workers. Cloudflare publishes type definitions to [GitHub](https://github.com/cloudflare/workers-types) and [npm](https://www.npmjs.com/package/@cloudflare/workers-types) (`npm install -D @cloudflare/workers-types`). All APIs provided in Workers are fully typed, and type definitions are generated directly from [workerd](https://github.com/cloudflare/workerd), the open-source Workers runtime.
15+
We recommend you generate types for your Worker by running [`wrangler types`](/workers/wrangler/commands/#types). Cloudflare also publishes type definitions to [GitHub](https://github.com/cloudflare/workers-types) and [npm](https://www.npmjs.com/package/@cloudflare/workers-types) (`npm install -D @cloudflare/workers-types`).
1616

17-
### Generate types that match your Worker's configuration (experimental)
17+
<h3 id="generate-types">
18+
Generate types that match your Worker's configuration
19+
</h3>
1820

1921
Cloudflare continuously improves [workerd](https://github.com/cloudflare/workerd), the open-source Workers runtime.
20-
Changes in workerd can introduce JavaScript API changes, thus changing the respective TypeScript types. For example, the [`urlsearchparams_delete_has_value_arg`](/workers/configuration/compatibility-flags/#urlsearchparams-delete-and-has-value-argument) compatibility flag adds optional arguments to some methods, in order to support new additions to the WHATWG URL standard API.
22+
Changes in workerd can introduce JavaScript API changes, thus changing the respective TypeScript types.
2123

22-
This means the correct TypeScript types for your Worker depend on:
24+
This means the correct types for your Worker depend on:
2325

24-
1. Your Worker's [Compatibility Date](/workers/configuration/compatibility-dates/).
25-
2. Your Worker's [Compatibility Flags](/workers/configuration/compatibility-flags/).
26+
1. Your Worker's [compatibility date](/workers/configuration/compatibility-dates/).
27+
2. Your Worker's [compatibility flags](/workers/configuration/compatibility-flags/).
28+
3. Your Worker's bindings, which are defined in your [Wrangler configuration file](/workers/wrangler/configuration).
29+
4. Any [module rules](/workers/wrangler/configuration/#bundling) you have specified in your Wrangler configuration file under `rules`.
2630

27-
For example, if you have `compatibility_flags = ["nodejs_als"]` in your [Wrangler configuration file](/workers/wrangler/configuration/), then the runtime will allow you to use the [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) class in your worker code, but you will not see this reflected in the type definitions in `@cloudflare/workers-types`.
31+
For example, the runtime will only allow you to use the [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage) class if you have `compatibility_flags = ["nodejs_als"]` in your [Wrangler configuration file](/workers/wrangler/configuration/). This should be reflected in the type definitions.
2832

29-
In order to solve this issue, and to ensure that your type definitions are always up-to-date with your compatibility settings, you can dynamically generate the runtime types (as of `wrangler 3.66.0`):
33+
To ensure that your type definitions always match your Worker's configuration, you can dynamically generate types by running:
3034

31-
```bash
32-
npx wrangler types --experimental-include-runtime
33-
```
35+
<PackageManagers type="exec" pkg="wrangler" args={"types"} />
3436

35-
This will generate a `d.ts` file and (by default) save it to `.wrangler/types/runtime.d.ts`. You will be prompted in the command's output to add that file to your `tsconfig.json`'s `compilerOptions.types` array.
37+
See [the `wrangler types` command docs](/workers/wrangler/commands/#types) for more details.
3638

37-
If you would like to commit the file to git, you can provide a custom path. Here, for instance, the `runtime.d.ts` file will be saved to the root of your project:
39+
:::note
3840

39-
```bash
40-
npx wrangler types --experimental-include-runtime="./runtime.d.ts"
41-
```
41+
<Render file="wrangler-commands/runtime-types" product="workers" />
4242

43-
**Note: To ensure that your types are always up-to-date, make sure to run `wrangler types --experimental-include-runtime` after any changes to your config file.**
43+
:::
4444

45-
See [the full list of available flags](/workers/wrangler/commands/#types) for more details.
45+
This will generate a `d.ts` file and (by default) save it to `worker-configuration.d.ts`. This will include `Env` types based on your Worker bindings _and_ runtime types based on your Worker's compatibility date and flags.
4646

47-
#### Migrating from `@cloudflare/workers-types` to `wrangler types --experimental-include-runtime`
47+
You should then add that file to your `tsconfig.json`'s `compilerOptions.types` array. If you have the `nodejs_compat` compatibility flag, you should also install `@types/node`.
4848

49-
The `@cloudflare/workers-types` package provides runtime types for each distinct [compatibility date](https://github.com/cloudflare/workerd/tree/main/npm/workers-types#compatibility-dates), which is specified by the user in their `tsconfig.json`. But this package is superseded by the `wrangler types --experimental-include-runtime` command.
49+
You can commit your types file to git if you wish.
5050

51-
Here are the steps to switch from `@cloudflare/workers-types` to using `wrangler types` with the experimental runtime inclusion:
51+
:::note
5252

53-
##### Uninstall `@cloudflare/workers-types`
53+
To ensure that your types are always up-to-date, make sure to run `wrangler types` after any changes to your config file.
5454

55-
<Tabs> <TabItem label="npm">
55+
:::
5656

57-
```sh
58-
npm uninstall @cloudflare/workers-types
59-
```
57+
<h3 id="migrating">
58+
Migrating from `@cloudflare/workers-types` to `wrangler types`
59+
</h3>
6060

61-
</TabItem> <TabItem label="yarn">
61+
We recommend you use `wrangler types` to generate runtime types, rather than using the `@cloudflare/workers-types` package, as it generates types based on your Worker's [compatibility date](https://github.com/cloudflare/workerd/tree/main/npm/workers-types#compatibility-dates) and `compatibility flags`, ensuring that types match the exact runtime APIs made available to your Worker.
6262

63-
```sh
64-
yarn remove @cloudflare/workers-types
65-
```
63+
:::note
6664

67-
</TabItem> <TabItem label="pnpm">
65+
There are no plans to stop publishing the `@cloudflare/workers-types` package, which will still be the recommended way to type libraries and shared packages in the workers environment.
6866

69-
```sh
70-
pnpm uninstall @cloudflare/workers-types
71-
```
67+
:::
7268

73-
</TabItem> </Tabs>
69+
#### 1. Uninstall `@cloudflare/workers-types`
7470

75-
##### Generate runtime types using wrangler
71+
<PackageManagers type="remove" pkg="@cloudflare/workers-types" />
7672

77-
```bash
78-
npx wrangler types --experimental-include-runtime
79-
```
73+
#### 2. Generate runtime types using Wrangler
8074

81-
This will generate a `.d.ts` file, saved to `.wrangler/types/runtime.d.ts` by default.
75+
<PackageManagers type="exec" pkg="wrangler" args={"types"} />
8276

83-
##### Update your `tsconfig.json` to include the generated types
77+
This will generate a `.d.ts` file, saved to `worker-configuration.d.ts` by default. This will also generate `Env` types. If for some reason you do not want to include those, you can set `--include-env=false`.
78+
79+
You can now remove any imports from `@cloudflare/workers-types` in your Worker code.
80+
81+
:::note
82+
83+
<Render file="wrangler-commands/runtime-types" product="workers" />
84+
85+
:::
86+
87+
#### 3. Make sure your `tsconfig.json` includes the generated types
8488

8589
```json
8690
{
8791
"compilerOptions": {
88-
"types": ["./.wrangler/types/runtime"]
92+
"types": ["worker-configuration.d.ts"]
8993
}
9094
}
9195
```
9296

9397
Note that if you have specified a custom path for the runtime types file, you should use that in your `compilerOptions.types` array instead of the default path.
9498

95-
##### Update your scripts and CI pipelines
99+
#### 4. Add @types/node if you are using [`nodejs_compat`](/workers/runtime-apis/nodejs/) (Optional)
100+
101+
If you are using the `nodejs_compat` compatibility flag, you should also install `@types/node`.
102+
103+
<PackageManagers type="add" pkg="@types/node" />
104+
105+
Then add this to your `tsconfig.json`.
106+
107+
```json
108+
{
109+
"compilerOptions": {
110+
"types": ["worker-configuration.d.ts", "node"]
111+
}
112+
}
113+
```
114+
115+
#### 5. Update your scripts and CI pipelines
96116

97-
When switching to `wrangler types --experimental-include-runtime`, you'll want to ensure that your development process always uses the most up-to-date types. The main thing to remember here is that - regardless of your specific framework or build tools - you should run the `wrangler types --experimental-include-runtime` command before any development tasks that rely on TypeScript. This ensures your editor and build tools always have access to the latest types.
117+
Regardless of your specific framework or build tools, you should run the `wrangler types` command before any tasks that rely on TypeScript.
98118

99-
Most projects will have existing build and development scripts, as well as some type-checking. In the example below, we're adding the `wrangler types --experimental-include-runtime` before the type-checking script in the project:
119+
Most projects will have existing build and development scripts, as well as some type-checking. In the example below, we're adding the `wrangler types` before the type-checking script in the project:
100120

101121
```json
102122
{
103123
"scripts": {
104124
"dev": "existing-dev-command",
105-
"build": "-existing-build-command",
106-
"type-check": "wrangler types --experimental-include-runtime && tsc"
125+
"build": "existing-build-command",
126+
"generate-types": "wrangler types",
127+
"type-check": "generate-types && tsc"
107128
}
108129
}
109130
```
110131

111-
In CI, you may have separate build and test commands. It is best practice to run `wrangler types --experimental-include-runtime` before other CI commands. For example:
132+
We recommend you commit your generated types file for use in CI. Alternatively, you can run `wrangler types` before other CI commands, as it should not take more than a few seconds. For example:
112133

113134
<Tabs> <TabItem label="npm">
114135

@@ -136,26 +157,6 @@ In CI, you may have separate build and test commands. It is best practice to run
136157
137158
</TabItem> </Tabs>
138159
139-
By integrating the `wrangler types --experimental-include-runtime` command into your workflow this way, you ensure that your development environment, builds, and CI processes always use the most accurate and up-to-date types for your Cloudflare Worker, regardless of your specific framework or tooling choices.
140-
141-
### Known issues
142-
143-
#### Transitive loading of `@types/node` overrides `@cloudflare/workers-types`
144-
145-
Your project's dependencies may load the `@types/node` package on their own. As of `@types/[email protected]` that package now overrides `Request`, `Response` and `fetch` types (possibly others) specified by `@cloudflare/workers-types` causing type errors.
146-
147-
The way to get around this issue currently is to pin the version of `@types/node` to `20.8.3` in your `package.json` like this:
148-
149-
```json
150-
{
151-
"overrides": {
152-
"@types/node": "20.8.3"
153-
}
154-
}
155-
```
156-
157-
For more information, refer to [this GitHub issue](https://github.com/cloudflare/workerd/issues/1298).
158-
159160
### Resources
160161
161162
- [TypeScript template](https://github.com/cloudflare/workers-sdk/tree/main/packages/create-cloudflare/templates/hello-world/ts)

src/content/docs/workers/observability/logs/logpush.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Workers Trace Events Logpush is not available for zones on the [Cloudflare China
2424
## Verify your Logpush access
2525

2626
:::note[Wrangler version]
27-
Minimum required Wrangler version: 2.2.0. Check your version by running `wrangler version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
27+
Minimum required Wrangler version: 2.2.0. Check your version by running `wrangler --version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
2828
:::
2929

3030
To configure a Logpush job, verify that your Cloudflare account role can use Logpush. To check your role:

src/content/docs/workers/observability/logs/workers-logs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To send logs to a third party, use [Workers Logpush](/workers/observability/logs
2424
## Enable Workers Logs
2525

2626
:::note[Wrangler version]
27-
Minimum required Wrangler version: 3.78.6. Check your version by running `wrangler version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
27+
Minimum required Wrangler version: 3.78.6. Check your version by running `wrangler --version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
2828
:::
2929

3030
You must add the observability setting for your Worker to write logs to Workers Logs. Add the following setting to your Worker's Wrangler file and redeploy your Worker.

src/content/docs/workers/tutorials/github-sms-notifications-using-twilio/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ async fetch(request, env, ctx) {
237237
};
238238
```
239239

240-
Run the `npx wrangler publish` command to redeploy your Worker project:
240+
Run the `npx wrangler deploy` command to redeploy your Worker project:
241241

242242
```sh
243243
npx wrangler deploy

0 commit comments

Comments
 (0)