Skip to content

pg bundling isuses with nitro v3 and cloudflare #4010

@medz

Description

@medz

Describe the feature

While using Nitro, the current bundler has encountered many strange issues, such as:

  • WASM cannot extend beyond the project scope.

  • The runtime requires WASM, but it doesn't handle platform-compliant formats well.

  • External non-standard ESM dependencies (e.g., Prisma ORM, many of its dependencies are CJS, or pg packages, whose ESM support requires writing an ESM file that depends on internal CJS).

  • Non-standard Node module dependencies, such as require("events").

These problems often occur with Cloudflare workers, and updating the current bundling configuration makes it difficult to handle various situations (usually occurring in other dependent packages).

Through testing, wrangler's built-in bundling handles all platform-compliant situations. For example, Hono is clever in that it doesn't handle bundling itself, so using Hono in the same situation works without problems.

For example, a recent problem I encountered involved needing to depend on Prisma ORM and then using the pg driver. Bundling was flawless, but deployment to Cloudflare failed.


Q: So, what is pure packaging mode support?

Simply put, Nitro doesn't handle any packaging; it simply writes the code from a virtual directory to a specific folder and provides an entry file. Alternatively, Nitro provides a virtual entry point (which the user imports and then re-exports).

This way, all code dependencies are located in the original TS/JS files and the pkg folder under node_modules.

Major Benefits

Cloudflare deployment will no longer be hindered; for example, features like cloudflare.exports.ts can be omitted.

Implementation Difficulty

Not yet investigated, but based on previous understanding of Nitro's internal packaging:

  1. You still need to run nitro build.

  2. Set builder in nitro.config.ts to false to support pure packaging mode.

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions