Skip to content

🐛 BUG: wrangler pages deploy throws misleading error when experimental:nodejs_compat_v2 is enabled #6288

@irvinebroque

Description

@irvinebroque

Which Cloudflare product(s) does this pertain to?

Wrangler

What version(s) of the tool(s) are you using?

3.57.1

What version of Node are you using?

v22.3.0

What operating system and version are you using?

Mac Sonoma 14.5

Describe the Bug

How to reproduce

Repro

With experimental:nodejs_compat_v2, run wrangler pages deploy...

✘ [ERROR] Could not resolve "fs"

    ../build/server/index.js:6:15:
      6 │ import fs from "fs";
        ╵                ~~~~

  The package "fs" wasn't found on the file system but is built into node.
  Add the "nodejs_compat" compatibility flag to your Pages project and make sure to prefix the module name with "node:" to enable Node.js compatibility.

This error isn't right — I already have experimental:nodejs_compat_v2 enabled, but it's telling me I need to enable the nodejs_compat flag.

If I add the node: specifier to fs, I get a different error

✘ [ERROR] Deployment failed!

  Failed to publish your Function. Got error: No such compatibility flag:
  experimental:nodejs_compat_v2

But to the customer — that's what you told me in your docs I was supposed to enable :)

Effectively — we're just returning the same error we'd return if you enabled nodejs_compat (link to repro)

What should we do about it?

When I run wrangler pages deploy with experimental:nodejs_compat_v2...

  1. The nodejs_compat_v2 compat flag should be enabled (and the experimental: prefix properly removed, as is already current behavior for Workers)
  2. No polyfills should be added to the Worker (I am assuming that it is not viable to add unenv to an already bundled Pages project — that the addition of unenv needs to be handled by the framework. If that's not the case, let me know!)

Please provide a link to a minimal reproduction

irvinebroque/remix-d1#8

Please provide any relevant error logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pagesRelating to Pages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions