ℹ️ Note: symlinking the node_modules folder is a simpler solution.
- Run
make. - Create a Node JS 14 Lambda Function from
dist/lambda-nodejs14.zip. - Create a Lambda Layer from
dist/layer.zip. - Attach layer to the function.
- Invoke function. Function will load an ESM from the layer.
The NODE_PATH variable is not supported by the ESM loader in Node, as seen here. In addition, the NODE_PATH is not part of resolving import specifiers, which means the layer cannot be reached.
The workaround would be to use a module from a layer, which would be to expose the dynamic import function from the module that you require.
Using that workaround I cannot
import { s3 } from 'esm_in_layer'but use explicit, async loading. Adding this boilerplate code to all lambdas adds additional workload which I want to avoid.