-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find package when using ES Module and Lambda Layer #3386
Comments
No one else had this issue? |
same issue here: in my case it cannot find package 'aws-lambda-fastify' i tried without success:
|
Having same issue Cannot find package 'serverless-http' imported from /var/task/lambda.js I only have that package in my lambda. It works without es module but unfortunately the app can only be built with ES module support due to external requirements. |
I've seen this error both importing other parts of my own source and importing individual source files from I couldn't use the suggested work-around of adding Instead, I ended up post-processing the
|
any update on this? @RanVaknin https://github.com/coderbyheart/aws-lambda-esm-with-layer Here are two supposed "workarounds" I found. Yet to implement either |
Would be good to get an update. What is the point in implementing ES module support when it doesn't work with Layers?! Anyone got experience with the workarounds? |
Any updates or fix for this issue? |
Kinda. Use Node 18. Otherwise, no, no official fix for other versions and I would say its unlikely, knowing AWS' track record with updates. |
You can get it working by specifying direct path to the imported file as /opt/nodejs/node_modules/xxx_your_package_xxx . // all of the below is the Lambda@Edge code that supports only Node16. // 2. Determine where your zipped layer ends up in the Lambda environment under /opt, by uncommenting and iterating over this: // 3. Once you know where your layers reside under the /opt/..., use the fully qualified path to the imported file |
Hi @paul-uz, @rnietoe, @jcuna, @jerith666, @djsjr, Basically, this seems to be an issue at the lambda side, and for that I have opened an internal ticket with the lambda team. In the meantime, while we wait for lambda team to answer, there is a workaround that we could use, which I found in the following post in stackoverflow, and is basically importing the package directly from the path. Actually what @serge7m says is correct. Example: import AWS from '/var/runtime/node_modules/aws-sdk/lib/aws.js'; So, a working example based on the sample code provide would be: import AWS from '/var/runtime/node_modules/aws-sdk/lib/aws.js';
const {Lambda} = AWS;
const lambda = new Lambda();
export const handler = async (event) => {
const eventSourceMappings = await lambda.listEventSourceMappings({ FunctionName: 'rpal-testlambda' }).promise();
const response = {
statusCode: 200,
body: JSON.stringify(eventSourceMappings)
};
return response;
}; Thanks! |
The AWS SDK for JavaScript team revisited this issue while testing Lambda Layers, and verified that the symlink workaround from https://github.com/vibe/aws-esm-modules-layer-support works. We recommend that workaround, as it's simpler. |
Since this is a limitation with Lambda and not actionable by the SDK team, I feel inclined to close this. Thanks, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
I am testing out using the new ES Module system, along with a Lambda Layer.
Here is my tsconfig file I used to compile my index.js file:
I set the
type
tomodule
in the lambda functions package.jsonHere is my package.json file I use for the Lambda Layer:
when I test the function, I get the following error:
The text was updated successfully, but these errors were encountered: