-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added no_nodejs_compat_v2 to notes #18765
base: production
Are you sure you want to change the base?
Conversation
Deploying cloudflare-docs with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to see an actual Compatibility Flag entry for this in the list below. You can create one by creating a file like ./src/content/compatibility-flags/nodejs-compat-v2.md
:
---
_build:
publishResources: false
render: never
list: never
name: "Node.js compatibility v2"
sort_date: "2024-09-23"
enable_date: "2024-09-23"
enable_flag: "nodejs_compat_v2"
disable_flag: "no_nodejs_compat_v2"
---
This flag allows you to import Node.js modules without the `node:` prefix and will polyfill additional Node.js modules and globals that are not available with `nodejs_compat` alone.
@@ -50,7 +50,7 @@ You can opt into improved Node.js compatibility by using `nodejs_compat_v2` inst | |||
additionally you can import Node.js modules without the `node:` prefix and use polyfilled Node.js modules and globals that are not available with `nodejs_compat`. | |||
|
|||
On September 23, 2024, `nodejs_compat` will use the improved Node.js compatibility currently enabled with `nodejs_compat_v2`. This will require updating your | |||
compatibility_date to 2024-09-23 or later. | |||
compatibility_date to 2024-09-23 or later. If you want to explicitly disable the Node.js v2 compatibility features to reduce bundle size, you can use the `no_nodejs_compat_v2` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take it or leave it:
compatibility_date to 2024-09-23 or later. If you want to explicitly disable the Node.js v2 compatibility features to reduce bundle size, you can use the `no_nodejs_compat_v2` flag. | |
compatibility_date to 2024-09-23 or later. If you want to explicitly disable these improved Node.js compatibility features (for example, to reduce bundle size), you can use the `no_nodejs_compat_v2` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to reduce bundle size
Maybe we should explicitly explain the difference between nodejs_compat
and nodejs_compat_v2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vicb @GregBrimble
I feel like, ideally, we’d just remove “to reduce bundle size” and then link “improved Node.js compatibility” to a an explanation in this article of the differences/improvements of v2. Could one of you either draft those v2 improvements here or in another PR or just list them for me here and I’ll add it? Thank you!
(But I also saw your other comments and I will make a task to take a more holistic look at improving the nodejs compat info, in general)
cc: @mikenomitch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(For the purposes of people who might want to use the no_nodejs_compat_v2 flag, we should also make any differences clear that could be disadvantages in some situations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like, ideally, we’d just remove “to reduce bundle size” and then link “improved Node.js compatibility” to a an explanation in this article of the differences/improvements of v2
+1 to remove details in most places where we and mention the compat flags and link to "this article".
(However I think that the text we are commenting on is located in the article).
About the differences:
v2 improves Node compatibility by using unenv. unenv implements some node modules that are not implemented by workerd. We have to bundle those implementations alongside the user code which explain why the bundle siize increases. But workerd is slowly catching up by implementing modules so that the unenv overhead is less and less significant. On top of that we have increased the allowed bundle size. Another reason for which bundle size is becoming less of a concern.
IMO the other differences "the globals Buffer and process are available everywhere" deserve to be describe. The only reason why I have seen no_nodejs_compat_v2
is to disable process
update. @petebacondarwin has more details.
@anonrig Are there any other differences backed in nodejs_compat_v2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petebacondarwin @anonrig
Following up on @vicb's question above since it would be very useful to include this information. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could avoid mentioning unenv directly. It is more of an implementation detail.
Really what we are saying is something along the lines of:
v2 augments the runtime's Node.js compatibility by bundling additional polyfills and globals into your Worker. You can disable adding the bundled polyfills, and only get the built-in runtime compatibility, by setting
nodejs_compat
+no_nodejs_compat_v2
. Disabling the bundled polyfills can reduce bundle size and avoid injecting some global variables but should only be used if you know what you are doing.
@@ -32,7 +32,7 @@ compatibility_date = "2024-09-23" | |||
</WranglerConfig> | |||
|
|||
:::note | |||
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later. | |||
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later. If you want to explicitly disable the Node.js v2 compatibility features to reduce bundle size, you can use the `no_nodejs_compat_v2` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take it or leave it:
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later. If you want to explicitly disable the Node.js v2 compatibility features to reduce bundle size, you can use the `no_nodejs_compat_v2` flag. | |
As of September 23rd, 2024, the `nodejs_compat` compatibility flag enables the exact same behavior as the `nodejs_compat_v2` compatibility flag, as long as your compatibility date is set to September 23rd, 2024 or later. If you want to explicitly disable these improved Node.js compatibility features (for example, to reduce bundle size), you can use the `no_nodejs_compat_v2` flag. |
@@ -50,7 +50,7 @@ You can opt into improved Node.js compatibility by using `nodejs_compat_v2` inst | |||
additionally you can import Node.js modules without the `node:` prefix and use polyfilled Node.js modules and globals that are not available with `nodejs_compat`. | |||
|
|||
On September 23, 2024, `nodejs_compat` will use the improved Node.js compatibility currently enabled with `nodejs_compat_v2`. This will require updating your | |||
compatibility_date to 2024-09-23 or later. | |||
compatibility_date to 2024-09-23 or later. If you want to explicitly disable the Node.js v2 compatibility features to reduce bundle size, you can use the `no_nodejs_compat_v2` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to be more explicit and say "both nodejs_compat
and no_nodejs_compat_v2
"
A couple comments:
|
This code is useful to understand how this works
Basically using Using (It took me some time to figure out so it might be helpful to some people reading this issue) |
Right, but
Ah yes, absolutely. Thanks for catching that. Lemme go edit that suggestion to be just "This flag..." |
It's enable by default ONLY when nodejs_compat is used. I can not really think of a good way to set the date. Buy maybe we can expand the description to be very clear about that. |
I find it misleading as it might sound like v2 requires nodejs_compat. IMO the only sane way to explain this would be "implied by: nodejs_compat and compatibility_date >= 2024-09-23". Not sure if we need a row, explaining this in description would work. |
Looking at https://developers.cloudflare.com/workers/configuration/compatibility-flags/, we do not have a en entry for So maybe we do not need an entry for There is an existing https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag section where we can add details. |
Yeah, we really should add both here. These listings also power APIs which are used by the dashboard for selecting compat flags/dates. |
I was thinking about exactly that yesterday (the dashboard list).
Note that this is only thoughts no strong opinions (as long as the docs accurately describe the flags) |
Yeah, whatever — I don't hugely care either way to be honest. I've said my piece :) PCX/Product can make calls about exactly how they want to describe and expose these. I'm sure it'll be fine either way. |
@vicb @GregBrimble Updated according to your feedback. Let me know what you think. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I added a few minor nits, not sure if they are even worth addressing.
|
||
On September 23, 2024, `nodejs_compat` will use the improved Node.js compatibility currently enabled with `nodejs_compat_v2`. This will require updating your | ||
compatibility_date to 2024-09-23 or later. | ||
If your compatibility date is before 2024-09-23 and you want to enable v2, add the `nodejs_compat_v2` in addition to the `nodejs_compat` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nits: before/after might be confusing (wrt to 09-23 included?)
If your compatibility date is before 2024-09-23 and you want to enable v2, add the `nodejs_compat_v2` in addition to the `nodejs_compat` flag. | |
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. |
@@ -45,7 +41,7 @@ Unless otherwise specified, implementations of Node.js APIs in Workers are inten | |||
|
|||
## Node.js API Polyfills | |||
|
|||
When you enable the `nodejs_compat` compatability flag and set your compatibility date to `2024-09-23` or later, in addition to enabling Node.js APIs in the Workers Runtime, [Wrangler](/workers/wrangler/) will use [unenv](https://github.com/unjs/unenv) to automatically detect uses of Node.js APIs, and add polyfills where relevant. | |||
To enable built-in Node.js APIs and add polyfills, you need to add the `nodejs_compat` compatibility flag to your `wrangler.toml`. 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrangler.toml
-> wrangler configuration (support for .json was recently added and is probably becoming the default)
@@ -46,11 +46,10 @@ Compatibility flags can be set when uploading a Worker using the [Workers Script | |||
## Node.js compatibility flag | |||
|
|||
:::note | |||
You can opt into improved Node.js compatibility by using `nodejs_compat_v2` instead of `nodejs_compat`. This provides the functionality of `nodejs_compat`, but | |||
additionally you can import Node.js modules without the `node:` prefix and use polyfilled Node.js modules and globals that are not available with `nodejs_compat`. | |||
[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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit: "by bundling additional polyfills and globals into your Worker"
wrangler does bundle additional polyfills but globals are not actually "bundled" - they are only exposed by workerd when v2 is added. However I think the current wording is ok - adding too many details might bring confusion.
Fixes #17608