Skip to content

Dynamic imports are causing code splitting issues in webpack #6612

@dgoemans

Description

@dgoemans

Checkboxes for prior research

Describe the bug

After upgrading to AWS SDK for JavaScript v3 (from 3.398.0 to 3.682.0), we encountered an issue where Webpack splits the build output into multiple chunks/folders containing AWS-related code (e.g., 699.js, etc).

Despite having Webpack configured to bundle all modules into a single JavaScript file, these chunks were still generated. Investigation revealed that several AWS SDK modules, such as @aws-sdk/credential-provider-env and @aws-sdk/credential-provider-http, use dynamic imports internally, triggering this behavior.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-*@3.682.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

Node 18

Reproduction Steps

  1. Use Webpack to bundle a project that imports AWS SDK v3 components (e.g., S3Client, DynamoDBClient).
  2. Configure Webpack with optimization.splitChunks: false and runtimeChunk: false to prevent code splitting.
  3. Observe that Webpack still splits certain AWS SDK modules into separate chunks/folders.

Observed Behavior

Instead of bundling all the dependencies into a single file, the code is split into separate chunks. When enabling named chunk IDs you can see that most of them are from the credentials providers, where dynamic imports are used.

Expected Behavior

Webpack should bundle all imported AWS SDK modules into the main JavaScript output, without creating additional chunks, especially when code splitting is explicitly disabled.

Possible Solution

Modifying webpack config to add aliases to force a non-dynamic import:

 resolve: {
    alias: {
      '@aws-sdk/credential-provider-env': path.resolve(
        __dirname,
        'node_modules/@aws-sdk/credential-provider-env/dist-cjs/index.js'
      ),
... insert all other modules here
  }
}

Additional Information/Context

Issue was already reported here:
#5990
by @nikimicallef

Metadata

Metadata

Labels

documentationThis is a problem with documentation.p2This is a standard priority issuequeuedThis issues is on the AWS team's backlogservice-apiThis issue is due to a problem in a service API, not the SDK implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions