cloudflare / cloudflare/workers-sdk
`@cloudflare/vite-plugin`: AWS SDK v3 (≥ @aws-sdk/core 3.974) crashes in dev — subpath-barrel re-exports resolve to `undefined`
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 187
Description
### Which Cloudflare product(s)?
`@cloudflare/vite-plugin`
### Summary
On a fresh install, any Worker that constructs an AWS SDK v3 client (e.g. `new DynamoDBClient({})`) throws at runtime in `vite dev`:
```
[vite] Internal server error: (0 , __vite_ssr_import_5__.emitWarningIfUnsupportedVersion) is not a function
at getRuntimeConfig (node_modules/@aws-sdk/client-dynamodb/dist-es/runtimeConfig.js:18:5)
at new DynamoDBClient (node_modules/@aws-sdk/client-dynamodb/dist-es/DynamoDBClient.js:20:27)
at Object.fetch (worker/index.ts)
```
The Worker's Vite environment runs `@aws-sdk/*` / `@smithy/*` through the SSR module runner, and it cannot resolve **named re-exports that pass through the subpath-barrel entrypoints** (`@aws-sdk/core/client`, `@smithy/core/client`) introduced in the current AWS SDK generation — the binding comes back `undefined`.
### Reproduction
Worker entry:
```ts
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
export default {
async fetch() {
new DynamoDBClient({ region: 'us-east-1' }); // throws during construction
return new Response('ok');
},
};
```
`package.json` (fresh install today resolves the broken generation):
```jsonc
"@aws-sdk/client-dynamodb": "^3.983.0" // → resolves 3.1081.0
// transitively: @aws-sdk/core 3.974.29, @smithy/smithy-client 4.14.6, @smithy/core 3.29.1
```
`wrangler.jsonc`: `"compatibility_flags": ["nodejs_compat"]`, `"compatibility_date": "2026-03-10"`.
Hit the Worker once → 500 with the error above.
### Environment
- `@cloudflare/vite-plugin`: 1.43.2 (also repro on 1.41.0)
- vite: 6.4.3
- wrangler: 4.108.0
- node: v22.17.0
- OS: macOS (darwin 25.5.0)
### Root cause
AWS reorganized the SDK internals so that top-level entrypoints re-export through subpath barrels. Example — installed `@aws-sdk/core@3.974.29`:
```js
// @aws-sdk/core/dist-es/index.js
export { emitWarningIfUnsupportedVersion, ... } from "@aws-sdk/core/client";
```
`@smithy/smithy-client@4.14.6` does the same via `@smithy/core/client`. The Worker environment's SSR runner resolves `emitWarningIfUnsupportedVersion` off that re-export chain as `undefined`, so calling it throws.
This is the downstream effect of an **intentional** AWS change — aws/aws-sdk-js-v3#7686 (v3.974.0, "Changes to AWS SDK internal package dependency version pinning"), which AWS closed as working-as-intended ("No changes are needed by AWS SDK users"). Because AWS declares every internal dep with `^caret` ranges, a fresh install always floats the entire `@aws-sdk/*` + `@smithy/*` tree into this generation.
The **previous generation resolves fine** (`@aws-sdk/core@3.973.27`, `@smithy/smithy-client@4.12.9`), because those define the exports locally / via relative paths rather than through the subpath barrel.
### What I tried (workarounds that do NOT work)
1. `environments..optimizeDeps.include: ['@aws-sdk/client-dynamodb', '@aws-sdk/lib-dynamodb']`
→ pre-bundles a standalone `@aws-sdk_client-dynamodb.js` (esbuild *does* resolve the barrel there), but the actual importer keeps its own copy and still throws.
2. Nested syntax `include: ['use-dynamodb > @aws-sdk/client-dynamodb']`
→ no effect (looks like vitejs/vite#16405 — `dep1 > dep2` not honored in the SSR/Worker environment).
3. `optimizeDeps.exclude` / `resolve.external` → rejected as incompatible with `@cloudflare/vite-plugin` (cloudflare/workers-sdk#9538).
### Current workaround
Pin the whole `@aws-sdk/*` + `@smithy/*` tree back to the last pre-3.974 generation via `resolutions` (yarn) / `overrides` (npm/pnpm). Pinning a single package skews (the newer middleware re-export from the newer `@aws-sdk/core/client`), so the entire generation must be pinned together.
### Expected
The Worker environment's dep optimizer / SSR runner should resolve named re-exports through AWS SDK v3's subpath-barrel entrypoints, so the current (default-installed) AWS SDK works in `vite dev` without version pinning.
### Related
- aws/aws-sdk-js-v3#7686 (the intentional v3.974.0 change)
- vitejs/vite#16405 (`dep1 > dep2` include not working)
- cloudflare/workers-sdk#9538 (`optimizeDeps.exclude` incompatible with the plugin)
Contributor guide
Research direction
Start by reproducing the failure in the @cloudflare/vite-plugin Worker environment with the AWS SDK DynamoDB example and inspect the SSR module runner and dependency optimizer paths. Trace named re-exports through @aws-sdk/core/client and @smithy/core/client, then add regression coverage showing that the current AWS SDK generation works in vite dev without version pinning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript, vite
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100