Skip to content

Bug: ERR_REQUIRE_ESM when using @workflow/world-postgres in Next.js App Router #258

@rolivegab

Description

@rolivegab

Describe the bug

When using @workflow/world-postgres with the Next.js App Router, the development server crashes with an ERR_REQUIRE_ESM error upon the first API request to a route that uses the workflow library.

Maybe the error occurs because @workflow/world-postgres is an ES Module ("type": "module"), but some part of the Next.js build process (seemingly triggered by the workflow library's internal runtime) attempts to load it using require()?

To Reproduce

  1. Create a Next.js App Router project.
  2. Install the following packages:
    • next: 15.3.5
    • workflow: 4.0.1-beta.11
    • @workflow/world-postgres: 4.1.0-beta.7
  3. Set up a simple API route (/api/test/route.ts) that imports start from workflow/api.
  4. Configure instrumentation.ts to initialize the postgres world.
  5. Run the development server (next dev) and send a POST request to the API route.

Expected behavior

The API route should execute the workflow without crashing the server.

Error Log

Error: require() of ES Module /path/to/project/node_modules/.pnpm/@[email protected]/.../node_modules/@workflow/world-postgres/dist/index.js from /path/to/project/apps/api2/index.js not supported.
Instead change the require of ... to a dynamic import() which is available in all CommonJS modules.
at createWorld (../../src/runtime/world.ts:47:14)
at getWorldHandlers (../../src/runtime/world.ts:74:17)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions