Skip to content

SDK fails to bundle in Convex (serverless V8 runtime) due to unconditional import("node:fs/promises") #5

Description

@Naol-bm

Environment

  • @runware/sdk version: > 1.3.4 (works with 1.3.4)
  • Platform: Convex – serverless platform that bundles functions for either the V8 runtime or Node.js runtime (via "use node" directive)
  • Bundler: Convex’s internal bundler (based on esbuild)

Problem

When using @runware/sdk in a Convex project (outside a file marked with "use node"), the bundler fails with:

✘ [ERROR] Could not resolve "node:fs/promises"

    node_modules/@runware/sdk/dist/index.js:2049:26:
      2049 │   const fs = await import("node:fs/promises");
           ╵                           ~~~~~~~~~~~~~~~~~~

The package "node:fs/promises" 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.

The SDK unconditionally imports node:fs/promises using a dynamic import(), which is not available in the default V8 runtime used by Convex (and many other bundlers that target non‑Node environments).

Expected behaviour

The SDK should work in any JavaScript environment (browser, V8, Node) without forcing the consumer to mark all using files with "use node" (Node.js runtime).
If Node.js‑specific modules are required, they should be conditionally loaded (e.g., try/catch or check for typeof process !== 'undefined'), or the SDK should provide separate entry points for Node.js and browser/V8.

Steps to reproduce

  1. Create a new Convex project (bunx convex dev).
  2. Install @runware/sdk version > 1.3.4 (e.g., 1.4.0).
  3. Import and call any function from the SDK inside a Convex query, mutation, or action without adding "use node" at the top of the file.
  4. Run bunx convex dev – the error appears.

Workaround (for users)

  • Add "use node" to the file that imports the SDK, which forces those functions to run in a Node.js runtime.
    However, this forces the whole file (and all its imports) to be Node‑only, which may not be desirable if other parts of the file are V8‑optimised.

Suggested fix

  • Replace the unconditional await import("node:fs/promises") with a conditional import that only loads the module when running in a Node.js environment. For example:
    let fs;
    if (typeof process !== 'undefined' && process.versions?.node) {
      fs = await import("node:fs/promises");
    }
  • Alternatively, use a try/catch around the import and fallback to a no‑op or throw a clear error if the functionality is required.
  • Consider providing a browser‑compatible build (e.g., with browser field in package.json) to avoid bundling Node‑specific code altogether.

Additional context

  • Version 1.3.4 works fine in Convex without "use node".
  • This issue affects any bundler or environment that does not support Node.js built‑ins, not just Convex.

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