-
Notifications
You must be signed in to change notification settings - Fork 700
Description
Reproduction link or steps
Rolldown is either erroring or tree-shaking away parts of the AWS JavaScript SDK v3. I think it's something to do with dynamic imports but I haven't had a chance to dive much deeper!
Here's a minimal repo which reproduces the issue: https://github.com/cogwirrel/bugs/tree/rolldown-dynamic-import-aws-sdk
What is expected?
All used code to be included in the bundle.
What is actually happening?
The fromIni method from @aws-sdk/credential-provider-ini gets stripped out when inlineDynamicImports is true, causing an error at runtime when creating AWS service clients.
Rolldown resolves to the dist-cjs/index.js file in node modules for this dependency, which looks like:
'use strict';
var sharedIniFileLoader = require('@smithy/shared-ini-file-loader');
var propertyProvider = require('@smithy/property-provider');
var client = require('@aws-sdk/core/client');
const resolveCredentialSource = (credentialSource, profileName, logger) => {
const sourceProvidersMap = {
EcsContainer: async (options) => {
const { fromHttp } = await import('@aws-sdk/credential-provider-http');
const { fromContainerMetadata } = await import('@smithy/credential-provider-imds');
logger?.debug("@aws-sdk/credential-provider-ini - credential_source is EcsContainer");
return async () => propertyProvider.chain(fromHttp(options ?? {}), fromContainerMetadata(options))().then(setNamedProvider);
},
...
const fromIni = (_init = {}) => async ({ callerClientConfig } = {}) => {
...
};
exports.fromIni = fromIni;But rolldown's output strips out everything below the initial requires:
//#region node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js
var require_dist_cjs$3 = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js": ((exports) => {
var sharedIniFileLoader$1 = require_dist_cjs$21();
var propertyProvider$1 = require_dist_cjs$30();
var client = (init_client(), __toCommonJS$8(client_exports));
}) });
//#endregion
This causes an error at runtime when creating SDK clients as the fromIni method is missing.
When inlineDynamicImports is omitted, Rolldown throws an error:
thread '<unnamed>' panicked at crates/rolldown/src/module_finalizers/mod.rs:972:83:
no entry found for key
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at crates/rolldown/src/module_finalizers/mod.rs:972:83:
no entry found for key
ERROR Panic in async function
When I disable tree shaking it works as expected.
System Info
System:
OS: macOS 15.7.1
CPU: (16) arm64 Apple M4 Max
Memory: 735.69 MB / 128.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 22.14.0 - /Users/jack/.nvm/versions/node/v22.14.0/bin/node
Yarn: 1.22.22 - /Users/jack/.nvm/versions/node/v22.14.0/bin/yarn
npm: 10.9.2 - /Users/jack/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.15.1 - /Users/jack/.nvm/versions/node/v22.14.0/bin/pnpm
bun: 1.1.45 - /Users/jack/.bun/bin/bun
Browsers:
Chrome: 141.0.7390.77
Firefox: 143.0.1
Safari: 26.0.1
npmPackages:
rolldown: 1.0.0-beta.43 => 1.0.0-beta.43Any additional comments?
I'm using rolldown as the bundler for the Nx Plugin for AWS - this vends "generators" which set up AWS projects for you.
When working with AWS you use the SDK a lot, so it's important that this gets bundled correctly. I can work around this with a plugin that disables tree-shaking for the SDK, but it'd be much better not to have to vend this workaround in our generators.