-
Notifications
You must be signed in to change notification settings - Fork 638
Description
Describe the feature
In serverless environments (e.g. Cloudflare Workers), the Node.js filesystem APIs aren’t available. Currently, S3Client attempts to load configuration from the filesystem, which causes runtime errors.
Although the SDK exposes a runtime field:
/**
* The runtime environment.
* @internal
*/
runtime?: string;it appears to be for internal use and doesn’t affect how the configuration is loaded.
Use Case
Using S3Client in serverless environments such as Cloudflare Workers, the SDK tries to read configuration using Node filesystem API (like fs.readFile), which results in errors since it is not available.
Steps to Reproduce
- Run
S3Clientin a Cloudflare Worker. - The SDK tries to read configuration files using Node APIs.
- The runtime throws an error due to missing fs support
fs.readFile is not implemented yet!.
Expected Behavior
There should be a way to instantiate S3Client such that it uses the browser runtime configuration without depending on Node’s filesystem.
Actual Behavior
The SDK attempts to load Node configuration using various providers -including the filesystem- even when all required configuration values are already passed directly to the client constructor.
Proposed Solution
Provide an option to force the S3Client to use the browser runtime configuration or use a defined configuration provider (like only from the constructor) instead of using all providers.
Other Information
I have noticed that package.json contains these fields
"main": "./dist-cjs/index.js",
"browser": {
"./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser"
},
"react-native": {
"./dist-es/runtimeConfig": "./dist-es/runtimeConfig.native"
},What worked for me so far was to manually change this line in node_modules\@aws-sdk\client-s3\dist-cjs\index.js:
// From this
var import_runtimeConfig = require("././runtimeConfig");
// To this
var import_runtimeConfig = require("././runtimeConfig.browser");Is there a better workaround to make a single dependency build for the browser runtime rather than for example manually patching it with patch-package? Nuxt uses rollup to build server packages, and I have tried aliasing imports and replacing string occurrences but couldn't get it to work.
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
SDK version used
"@aws-sdk/client-s3": "3.726.1"
Environment details (OS name and version, etc.)
"nuxt": "^3.12.3", Worker Compatibility Date 2025-10-15