-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
Description
Describe the bug
When attempting to use ESBuild exporting to ESM via a AWS CDK with @datadog/datadog-api-client
I get the following error:
{
"errorType": "Error",
"errorMessage": "Dynamic require of \"stream\" is not supported",
"trace": [
"Error: Dynamic require of \"stream\" is not supported",
" at file:///var/task/index.mjs:11:9",
" at node_modules/node-fetch/lib/index.js (file:///var/task/index.mjs:3209:34)",
" at __require2 (file:///var/task/index.mjs:14:50)",
" at node_modules/cross-fetch/dist/node-ponyfill.js (file:///var/task/index.mjs:4443:21)",
" at __require2 (file:///var/task/index.mjs:14:50)",
" at node_modules/@datadog/datadog-api-client/dist/packages/datadog-api-client-common/http/isomorphic-fetch.js (file:///var/task/index.mjs:9089:25)",
" at __require2 (file:///var/task/index.mjs:14:50)",
" at node_modules/@datadog/datadog-api-client/dist/packages/datadog-api-client-common/configuration.js (file:///var/task/index.mjs:9425:30)",
" at __require2 (file:///var/task/index.mjs:14:50)",
" at node_modules/@datadog/datadog-api-client/dist/packages/datadog-api-client-v1/apis/AWSIntegrationApi.js (file:///var/task/index.mjs:43946:27)"
]
}
To Reproduce
Example function configuration
// CDK Lambda function
const function = new NodejsFunction(this, 'my-function', {
runtime: Runtime.NODEJS_20_X,
/* other config redacted */
bundling: {
sourceMap: true,
sourceMapMode: nodejs.SourceMapMode.INLINE,
format: OutputFormat.ESM
}
})
Expected behavior
Lambda function executes without error
Environment and Versions (please complete the following information):
- Node 20 as shown above.
- ESBuild
0.24.0
@datadog/datadog-api-client@1.29.0
Other Context
I tried with Node 22 as well as latest versions of @datadog/datadog-api-client
and still observed the same error.
The only way I could get this to work was to change OutputFormat.ESM
to OutputFormat.CJS
.
Related issue: evanw/esbuild#3637 (comment)