Skip to main content
← Back to list
01Issue
BugClosedSwamp Club
AssigneesNone

Bundler breaks tslib CJS/ESM interop for @aws-sdk/client-s3 dynamic imports

Opened by swampadmin · 5/1/2025

Description

Extension models that dynamically import npm:@aws-sdk/client-s3@3 fail at runtime with:

Cannot destructure property '__extends' of 'import_tslib.default' as it is undefined.

The swamp bundler statically inlines the dynamic await import("npm:@aws-sdk/client-s3@3") into the bundle. During this process, tslib's CJS module (require_tslib()) is wrapped in a __toESM bridge, but the resulting import_tslib.default is undefined when the bundle executes, causing the destructuring to fail.

Steps to Reproduce

  1. Create an extension model that uses await import("npm:@aws-sdk/client-s3@3") inside a method execute function
  2. Run swamp repo index
  3. Run any method on the model (e.g. swamp model method run my-s3 listBuckets --json)

Expected Behavior

The dynamic import should resolve correctly at runtime, loading @aws-sdk/client-s3 without bundling it.

Actual Behavior

The bundler inlines the AWS SDK and tslib into the .swamp/bundles/*.js output. The tslib CJS→ESM bridge fails because import_tslib.default is undefined.

Relevant bundle lines (.swamp/bundles/s3.js):

// tslib/2.8.1/modules/index.js
import_tslib = __toESM(require_tslib());
({ __extends, __assign, __rest, ... } = import_tslib.default);
// ^ import_tslib.default is undefined here

Environment

  • swamp: 20260305.011558.0-sha.b591ba6a
  • OS: macOS Darwin 25.3.0
  • Deno: v2.x
  • @aws-sdk/client-s3: v3 (latest)

Summary

This affects the bundler's handling of npm packages that use tslib's CJS/ESM dual-module pattern. The bundler should either:

  • Preserve dynamic await import() calls as-is (don't inline them), or
  • Correctly handle tslib's CJS→ESM interop during bundling

This blocks all extension models that use the AWS SDK (e.g. @bixu/s3, and would affect @bixu/instagram when it uses local file upload to S3).

02Bog Flow
OPENTRIAGEDIN PROGRESSCLOSED

Closed

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.