Skip to content
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

adapter-cloudflare should warn when server code uses Node builtins like fs #7702

Closed
kisaragi-hiu opened this issue Nov 17, 2022 · 2 comments
Closed

Comments

@kisaragi-hiu
Copy link

Describe the problem

Cloudflare uses its own JS runtime, so it is not possible to use Node builtins like fs or packages that specifically depend on Node like better-sqlite3. This is possible on, at least, Netlify.

Because IMO Cloudflare hasn't made this clear, a user might try to use them, correctly resulting in an error saying that some packages used are unavailable. However, this error is passed directly from esbuild, and reads like this as a result:

The package "util" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

This message reads as if it's emitted by SvelteKit or Vite and makes the user search for where to specify the platform: 'node', without realizing that it's a platform limitation. This reddit post is an example of a confused user:

I am building an app with SvelteKit and publishing it to Cloudflare Pages, but some packages I am using cannot access node native functions. […] This happened just after I added some server-side code, so that might be the reason, but Sveltekit supports that through Cloudflare workers, so I don't understand why. Help would be appreciated!

Describe the proposed solution

adapter-cloudflare should catch that the user is trying to use packages that are unavailable but are provided by Node, and replace esbuild's message with an explanation that they are unavailable on Cloudflare Workers. Perhaps something like:

The package "util" wasn't found on the file system but is built into node. Please note that Cloudflare does not run serverless functions in node and, as such, non-standard node builtins are unavailable when building for Cloudflare.

Alternatives considered

The explanation could be added to adapter-cloudflare's README instead.

Importance

nice to have

Additional Information

No response

@Conduitry
Copy link
Member

This would presumably fall under part of the work described in #3535.

@Rich-Harris
Copy link
Member

It does — it's definitely something we want to do, but I'm going to close this as a duplicate

@Rich-Harris Rich-Harris closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants