- Newest
- Most votes
- Most comments
The Node.js 22 runtime provided by AWS Lambda does not have the experimental feature to detect module syntax automatically enabled. This feature, which allows loading ECMAScript modules (ESM) using require()
, is not available in the Lambda-provided Node.js 22 runtime and cannot be enabled via an execution-time flag like --experimental-require-module
.
The reason for this is that AWS Lambda's Node.js 22 runtime is intended for production workloads, and experimental features are not enabled in the Lambda build. This means that even if you set the NODE_OPTIONS
environment variable with the --experimental-require-module
flag, it will not have the desired effect.
To use this experimental feature in AWS Lambda, you would need to deploy your own custom Node.js runtime. This can be done in two ways:
- Using a custom runtime
- Deploying your function as a container image
In both cases, you would need to build your own version of Node.js with the experimental module syntax detection enabled.
It's important to note that while the Node.js 22.12 LTS announcement suggests this behavior is now default, AWS Lambda's runtime is specifically built without this experimental feature enabled for stability reasons.
If you need to use this feature, consider creating a custom runtime or container image where you have more control over the Node.js environment and can enable experimental features. However, be aware that using experimental features in a production environment may introduce instability or unexpected behavior.
Sources
Node.js 22 runtime now available in AWS Lambda | AWS Compute Blog
Relevant content
- asked 10 months ago
- asked a year ago
This is incorrect. The LLM is confusing two different parts of the blog I initially linked. One saying that the
--experimental-require-module
flag should work, and a later section saying that there is another experimental feature that is not supported.