Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Node.js compatibility is now enabled by default"
description: Workers with a compatibility date of 2026-08-04 or later enable Node.js compatibility by default.
products:
- workers
date: 2026-08-04
---

import { WranglerConfig } from "~/components";

Workers now enable the `nodejs_compat` and `nodejs_compat_v2` compatibility
flags by default for [compatibility dates](/workers/configuration/compatibility-dates/)
of `2026-08-04` or later. These flags are not used for these compatibility
dates because the compatibility date enables the same behavior.

This means all [Node.js built-in APIs](/workers/runtime-apis/nodejs/) supported
by the Workers runtime are available by default, including `node:crypto`,
`node:buffer`, `node:stream`, `node:net`, `node:dns`, `node:fs`, `node:http`,
and more. npm packages that depend on these APIs will work without additional
configuration.

Workers using an earlier compatibility date are not affected. They can still
opt in by adding `nodejs_compat` to `compatibility_flags`.

New projects do not need to add either flag. Existing projects can update their
compatibility date without removing them. Wrangler, Miniflare, the Cloudflare
Vite plugin, and Vitest Pool Workers ignore these redundant flags when starting
the runtime.

To turn off Node.js compatibility completely, remove any `nodejs_compat` and
`nodejs_compat_v2` flags. Then add both of the following flags:

<WranglerConfig>

```toml
compatibility_date = "$today"
compatibility_flags = ["no_nodejs_compat", "no_nodejs_compat_v2"]
```

</WranglerConfig>

For more information, refer to the [Node.js compatibility documentation](/workers/runtime-apis/nodejs/).
5 changes: 4 additions & 1 deletion src/content/compatibility-flags/nodejs-compat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ _build:

name: "Node.js compatibility"
sort_date: "2023-01-15"
enable_date: "2026-08-04"
enable_flag: "nodejs_compat"
disable_flag: "no_nodejs_compat"
---

import { Render } from "~/components";

Enables [Node.js APIs](/workers/runtime-apis/nodejs/) in the Workers Runtime.
Enables [Node.js APIs](/workers/runtime-apis/nodejs/) in the Workers Runtime. For compatibility dates of `2026-08-04` or later, Workers enables both `nodejs_compat` and `nodejs_compat_v2` by default.

Note that some Node.js APIs are only enabled when your Worker's compatibility date is on or after the following dates:

Expand All @@ -31,4 +32,6 @@ The following stubs are enabled automatically only when `nodejs_compat` is enabl

When enabling `nodejs_compat`, we recommend using the latest version of [Wrangler CLI](/workers/wrangler/), and the latest compatibility date, in order to maximize compatibility. Some older versions of Wrangler inject additional polyfills that are no longer necessary when your Worker uses a more recent compatibility date, because they are provided by the Workers runtime.

For compatibility dates of `2026-08-04` or later, `nodejs_compat` and `nodejs_compat_v2` are not used because the compatibility date enables the same behavior. Existing projects do not need to remove these flags when updating their compatibility date. To turn off Node.js compatibility completely, remove the positive flags if present. Then add both `no_nodejs_compat` and `no_nodejs_compat_v2`.

If you see errors using a particular npm package on Workers, you should first try updating your compatibility date and use the latest version of [Wrangler CLI](/workers/wrangler/) or the [Cloudflare Vite Plugin](/workers/vite-plugin/). If you still encounter issues, please report them by [opening a GitHub issue](https://github.com/cloudflare/workers-sdk/issues/new?template=bug-template.yaml).
16 changes: 9 additions & 7 deletions src/content/docs/workers/configuration/compatibility-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,32 @@ Compatibility flags can be set when uploading a Worker using the [Workers Script
## Node.js compatibility flag

:::note
[The `nodejs_compat` flag](/workers/runtime-apis/nodejs/) also enables `nodejs_compat_v2` as long as your compatibility date is 2024-09-23 or later. The v2 flag improves runtime Node.js compatibility by bundling additional polyfills and globals into your Worker. However, this improvement increases bundle size.
[The `nodejs_compat` flag](/workers/runtime-apis/nodejs/) also enables `nodejs_compat_v2` for compatibility dates from `2024-09-23` through `2026-08-03`. The v2 flag improves Node.js compatibility by bundling additional polyfills and globals into your Worker. However, this improvement increases bundle size.

If your compatibility date is 2024-09-22 or before and you want to enable v2, add the `nodejs_compat_v2` in addition to the `nodejs_compat` flag.
If your compatibility date is after 2024-09-23, but you want to disable v2 to avoid increasing your bundle size, add the `no_nodejs_compat_v2` in addition to the `nodejs_compat flag`.
For compatibility dates through `2024-09-22`, add `nodejs_compat_v2` alongside `nodejs_compat` to turn on v2. For compatibility dates from `2024-09-23` through `2026-08-03`, add `no_nodejs_compat_v2` alongside `nodejs_compat` to use v1 only.
:::

A [growing subset](/workers/runtime-apis/nodejs/) of Node.js APIs are available directly as [Runtime APIs](/workers/runtime-apis/nodejs), with no need to add polyfills to your own code. To enable these APIs in your Worker, add the `nodejs_compat` compatibility flag to your [Wrangler configuration file](/workers/wrangler/configuration/):
A [growing subset](/workers/runtime-apis/nodejs/) of Node.js APIs are available directly as [Runtime APIs](/workers/runtime-apis/nodejs/), with no need to add polyfills to your own code.

<Render file="nodejs_compat" product="workers" />

For compatibility dates of `2026-08-04` or later, Workers enables both `nodejs_compat` and `nodejs_compat_v2` by default. These flags are not used for these compatibility dates because the compatibility date enables the same behavior. Wrangler, Miniflare, the Cloudflare Vite plugin, and Vitest Pool Workers ignore these redundant flags when starting the runtime. Existing projects do not need to remove them when updating their compatibility date. Omit them from new configurations.

To turn off Node.js compatibility completely for a compatibility date of `2026-08-04` or later, remove `nodejs_compat` and `nodejs_compat_v2` if present. Then add both of the following flags:

<WranglerConfig>

```jsonc
{
"compatibility_flags": [
"nodejs_compat"
"no_nodejs_compat",
"no_nodejs_compat_v2"
]
}
```

</WranglerConfig>

As additional Node.js APIs are added, they will be made available under the `nodejs_compat` compatibility flag. Unlike most other compatibility flags, we do not expect the `nodejs_compat` to become active by default at a future date.

The Node.js `AsyncLocalStorage` API is a particularly useful feature for Workers. To enable only the `AsyncLocalStorage` API, use the `nodejs_als` compatibility flag.

<WranglerConfig>
Expand Down
14 changes: 10 additions & 4 deletions src/content/docs/workers/runtime-apis/nodejs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ Cloudflare Workers provides a subset of Node.js APIs in two forms:

## Get Started

To enable built-in Node.js APIs and add polyfills, add the `nodejs_compat` compatibility flag to your [Wrangler configuration file](/workers/wrangler/configuration/), and ensure that your Worker's [compatibility date](/workers/configuration/compatibility-dates/) is 2024-09-23 or later. [Learn more about the Node.js compatibility flag and v2](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).
For compatibility dates of `2026-08-04` or later, Workers enables both `nodejs_compat` and `nodejs_compat_v2` by default. Built-in Node.js APIs and polyfills are available without additional configuration.

For these compatibility dates, `nodejs_compat` and `nodejs_compat_v2` are not used because the compatibility date enables the same behavior. Existing projects do not need to remove these flags when updating their compatibility date. Omit them from new configurations.

For compatibility dates from `2024-09-23` through `2026-08-03`, add the `nodejs_compat` compatibility flag to your [Wrangler configuration file](/workers/wrangler/configuration/) to opt in:

<WranglerConfig>

```jsonc
{
"compatibility_flags": ["nodejs_compat"],
"compatibility_date": "$today",
"compatibility_date": "2026-08-03",
"compatibility_flags": ["nodejs_compat"]
}
```

</WranglerConfig>

To turn off Node.js compatibility completely with a compatibility date of `2026-08-04` or later, remove the positive flags if present. Then add both `no_nodejs_compat` and `no_nodejs_compat_v2`. For configuration examples, refer to the [Node.js compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).

## Supported Node.js APIs

The runtime APIs from Node.js listed in this section with the status "🟢 supported" are currently natively supported in the Workers Runtime. Items listed as "🟡 partially supported" include usable APIs, but do not implement the complete Node.js API surface.
Expand Down Expand Up @@ -63,7 +69,7 @@ The runtime APIs from Node.js listed in this section with the status "🟢 suppo
| [Process](/workers/runtime-apis/nodejs/process/) | 🟢 supported |
| [Punycode](https://nodejs.org/docs/latest/api/punycode.html) (deprecated) | 🟢 supported |
| [Query strings](https://nodejs.org/docs/latest/api/querystring.html) | 🟢 supported |
| [Stream](/workers/runtime-apis/nodejs/streams/) | 🟢 supported |
| [Stream](/workers/runtime-apis/nodejs/streams/) | 🟢 supported |
| [String decoder](/workers/runtime-apis/nodejs/string-decoder/) | 🟢 supported |
| [Test runner](/workers/runtime-apis/nodejs/test/) | 🟡 partially supported |
| [Timers](/workers/runtime-apis/nodejs/timers/) | 🟢 supported |
Expand Down
4 changes: 1 addition & 3 deletions src/content/partials/workers/nodejs-compat-howto.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
{}

---

:::note

To enable built-in Node.js APIs and polyfills, add the nodejs_compat compatibility flag to your [Wrangler configuration file](/workers/wrangler/configuration/). This also enables nodejs_compat_v2 as long as your compatibility date is 2024-09-23 or later. [Learn more about the Node.js compatibility flag and v2](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).

For compatibility dates of `2026-08-04` or later, Workers enables both `nodejs_compat` and `nodejs_compat_v2` by default. These flags are not used for these compatibility dates. Existing projects do not need to remove them when updating their compatibility date. For earlier dates, add `nodejs_compat` to your [Wrangler configuration file](/workers/wrangler/configuration/) to opt in. For instructions to turn off Node.js compatibility, refer to the [Node.js compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).

:::
9 changes: 6 additions & 3 deletions src/content/partials/workers/nodejs_compat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

import { WranglerConfig } from "~/components";

To enable both built-in runtime APIs and polyfills for your Worker or Pages project, add the [`nodejs_compat`](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) [compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) to your [Wrangler configuration file](/workers/wrangler/configuration/), and set your compatibility date to September 23rd, 2024 or later. This will enable [Node.js compatibility](/workers/runtime-apis/nodejs/) for your Workers project.
For compatibility dates of `2026-08-04` or later, Workers and Pages projects enable both `nodejs_compat` and `nodejs_compat_v2` by default. Built-in runtime APIs and polyfills are available without additional configuration. These flags are not used for these compatibility dates. Existing projects do not need to remove them when updating their compatibility date.

If your compatibility date is before `2026-08-04`, add the [`nodejs_compat`](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) [compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag) to your [Wrangler configuration file](/workers/wrangler/configuration/) to opt in:

<WranglerConfig>

```jsonc
{
"compatibility_flags": [
"nodejs_compat"
],
"compatibility_date": "$today"
]
}
```

</WranglerConfig>

To turn off [Node.js compatibility](/workers/runtime-apis/nodejs/) completely for a compatibility date of `2026-08-04` or later, remove the positive flags if present. Then add both `no_nodejs_compat` and `no_nodejs_compat_v2`. For configuration examples, refer to the [Node.js compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag).
2 changes: 1 addition & 1 deletion worker/index.worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Cloudflare Docs", () => {
expect(urlFlag.experimental).toBe(false);

expect(nodeJsFlag).toBeDefined();
expect(nodeJsFlag.enable_date).toBe(null);
expect(nodeJsFlag.enable_date).toBe("2026-08-04");
});

it("pages framework configurations", async () => {
Expand Down
Loading