Skip to content

R2 binding mode fails to build under rolldown-vite: MISSING_EXPORT on optional @aws-sdk/* peers #105

Description

@jamiedavenport

Summary

Building a Cloudflare Worker that uses the R2 adapter in binding mode fails at build time under rolldown-vite when the optional @aws-sdk/* peers are not installed, even though the docs state the binding path needs none of them ("The Workers binding path, hybrid signing, and the lightweight fetch client need none of them - files-sdk alone is enough").

Environment

  • files-sdk: 2.2.0
  • vite: rolldown-vite (via vite-plus 0.2.2)
  • @cloudflare/vite-plugin: 1.45.1
  • No @aws-sdk/* packages installed

Reproduction

import { Files } from "files-sdk";
import { r2 } from "files-sdk/r2";

const files = new Files({ adapter: r2({ binding: env.STORAGE }) });

Build the Worker with the Cloudflare Vite plugin (vite build). The client build succeeds; the worker environment build fails:

[MISSING_EXPORT] "AbortMultipartUploadCommand" is not exported by "__vite-optional-peer-dep:@aws-sdk/client-s3:files-sdk".
[MISSING_EXPORT] "CompleteMultipartUploadCommand" is not exported by "__vite-optional-peer-dep:@aws-sdk/client-s3:files-sdk".
[MISSING_EXPORT] "CopyObjectCommand" is not exported by "__vite-optional-peer-dep:@aws-sdk/client-s3:files-sdk".
... (one per named import)

Cause

dist/r2/index.js keeps the AWS SDK engine behind a lazy await import("../s3/index.js") (lazyS3), which binding mode never executes. Rolldown still resolves the dynamic import at build time, follows the chunk's named imports of @aws-sdk/client-s3, and hard-errors against Vite's optional-peer-dep placeholder module. So the lazy-loading strategy that works at runtime is defeated during bundling. Same class of problem as #67, on the library surface instead of the CLI.

Expected

Binding mode bundles successfully without any @aws-sdk/* packages installed.

Workaround

Externalizing the never-executed path in the worker environment:

environments: { ssr: { build: { rollupOptions: { external: [/^@aws-sdk\//] } } } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions