-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Mark node:
as external for Node.js compatibility
#10544
Conversation
Co-authored-by: Willow (GHOST) <[email protected]>
Co-authored-by: Willow (GHOST) <[email protected]>
Co-authored-by: Ben McCann <[email protected]>
🦋 Changeset detectedLatest commit: 62dd0f5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I'm for this change but I think it may make sense having it behind some sort of config option, maybe |
I committed the suggested solution yesterday, not sure GitHub will notify the mods so that I quote your reply here. |
We should also add notes to the docs about this 🙏 We'll also will need some opinions from other maintainers before we can merge |
We generally try to avoid adding options, so unless there's a scenario where we don't want to do it, I would suggest we should always do it. However, I'm not sure whether it's enough? @cimnine reported in #10521 that they had to use Update: answering my own question. In #10521 the user was trying to use |
I'm still not 100% sure what the decision is re: various esbuild options being passable to the adapters - regardless this might be a nice change to reduce friction even if we do end up merging one of the esbuild option related prs - WDYT? @benmccann |
external: [ | ||
'__STATIC_CONTENT_MANIFEST', | ||
'cloudflare:*', | ||
...(options.nodeCompat ? ['node:*'] : []) |
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.
Whitelisting node:*
may be too aggressive. I think if we do that and someone uses an API like node:fs
then they won't find out their app is broken until they go to deploy it and it'd be better for that to occur during build. How about we switch it to just the list of APIs that Cloudflare supports with their node compatibility?
'node:assert', 'node:async_hooks', 'node:buffer', 'node:crypto', node:diagnostics_channel', node:events', node:path', node:process', node:stream', node:string_decoder', node:util'
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.
Yep that sounds legit. Cloudflare node_compat doesn't have modules like fs
, ...
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.
Is fixed in my latest commit
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.
May as well I remove AdapterOptions.nodeCompat
and always include those externals? 🤔
I merged it via the GitHub UI for you |
…r node compatibility
…user specify it twice
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.
Thank you!
We should remove the nodeCompat
option — there's no real value in it since it doesn't reflect or determine the project's compatibility flag. Better to only have to set it in one place.
Though it's probably worth generating a useful error when using unsupported modules like node:fs
, or supported-but-unprefixed modules like path
— will do that in a follow-up PR
documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md
Outdated
Show resolved
Hide resolved
documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md
Outdated
Show resolved
Hide resolved
@chientrm @benmccann @Rich-Harris Thanks! 🎉 |
@Rich-Harris While things are better, the adapter is still un-usable in some cases :/ For example trying to build a sveltekit project that uses When bundling a project with wrangler and the
This allows cloudflare workers and cloudflare pages projects to correctly build if there's a supported library such as "pg" that doesn't use "node:x" specifiers and use incompatible APIs. Note that there's also an issue with As a workaround, I'm using a forked version of the cloudflare adapter to inject the polyfills. Another gotcha is that the nodejs compatibility flag is not compatible with the polyfills while building with wrangler ... But it's still possible to build manually and enable the flag. I'm not sure what would be a possible solution, but it would be nice to enable esbuild custom settings for the cloudflare adapters. |
I am getting exceptions for every package I am trying to use that uses
Using:
I think, inside 'hooks.server.ts', got a custom handle which performs:
and I suspect that's the issue. Got "nodejs_compat" flag enabled, manually set via Cloudflare dashboard but it does not help. |
You're sure you have the flag for the preview environment, too? 😉 |
Yep, I even changed it to something else to see if the build fails and it does. My
Perhaps something is missing here... |
Please notice that node_compat and nodejs_compat are two completely different things. You can ask for support on discord Cloudflare. |
According to the documentation the flag name is: "nodejs_compat". Got you though. That means it requires manual deployment via wrangler. |
Is this supposed to work for Pages Adapter or do I have to use Worker adapter, because I am still getting the Could not resolve "crypto" or Could not resolve "node:crypto". |
Same question as @absktoday but for a dependency that is attempting to import |
Is the error at runtime on Cloudflare pages, or at buildtime either locally or on the CF pages builder @devinellis? What imports is the package using |
Sorry for the lack of detail:
Note if I am reading the CF docs right, |
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Explain
Last time I asked to add polyfill for
Buffer
API. That's no longer neccessary because Cloudflare added a bunch of nodejs APIs to Workers. They are all prefixed bynode:
.Example:
These APIs are enabled via compatibility_flags
nodejs_compat
and work for Workers, Pages andwrangler
.The APIs is here: Node.js compatibility