Skip to content

S3Express session authentication fails when @aws-sdk/client-s3 is bundled with esbuild #7665

@beastawakens

Description

@beastawakens

Describe the bug

When bundling @aws-sdk/client-s3 (v3.600+) with esbuild for use in a Node.js runtime (e.g., GitHub Actions custom JavaScript action), the S3Express session authentication middleware fails at runtime with an error related to AuthScheme having no name.

The same code works correctly when running unbundled with node_modules present.

SDK version number

@aws-sdk/client-s3@3.969.0 (specified as ^3.600.0 in package.json)

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node.js 20.x (GitHub Actions node20 runtime)

Reproduction Steps

  1. Create a simple Node.js project that uses @aws-sdk/client-s3:
// src/index.ts
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';

const client = new S3Client({ region: 'us-east-1' });

async function main() {
  const result = await client.send(new ListBucketsCommand({}));
  console.log(result.Buckets);
}

main();
  1. Bundle with esbuild:
esbuild src/index.ts --bundle --platform=node --target=node20 --outfile=dist/index.js --minify
  1. Run the bundled output:
node dist/index.js

Observed Behavior

The bundled code fails at runtime during S3 client initialization. The error occurs in the S3Express session authentication middleware, indicating that an AuthScheme object lacks a required name property.

The error manifests as a runtime exception from deep within the bundled SDK code, specifically in the S3Express credential/session handling logic that was introduced around v3.600.0.

Expected Behavior

The bundled code should work identically to unbundled code - S3 client should initialize and execute commands without errors.

Possible Solution

We found that pinning to @aws-sdk/client-s3@3.350.0 (a version from before S3Express support was added) resolves the issue. The bundle works correctly with this older version.

This suggests the S3Express middleware has some bundling incompatibility - possibly:

  • Dynamic imports that don't bundle correctly
  • Circular dependencies that break when flattened
  • Symbol or prototype chain issues when code is minified/tree-shaken

Additional context

  • Bundler: esbuild v0.20.0
  • Bundle flags: --bundle --platform=node --target=node20 --minify --tree-shaking=true
  • Use case: GitHub Actions custom JavaScript action that needs S3 access for bucket operations

Workaround: Pin @aws-sdk/client-s3 to version 3.350.0 (pre-S3Express era). This is not ideal as it prevents access to newer features and fixes.

We are not using S3Express buckets - only standard S3 buckets. Ideally, the S3Express middleware should not cause issues when S3Express features are not being used.

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions