- Newest
- Most votes
- Most comments
The error you're encountering suggests a compatibility issue between your code and the Lambda runtime environment. This TypeError occurs when the code attempts to define a property on a non-object, which is typically caused by unexpected undefined or null values.
Given that you mentioned using Node.js version 20, it's important to note that Lambda may not fully support this version yet, as Lambda tends to lag behind in supporting the latest Node.js versions. This could lead to unexpected behavior or errors when deploying code developed with newer Node.js features.
To resolve this issue, you could try the following steps:
-
Check the Lambda runtime: Ensure you're using a Node.js runtime version that's fully supported by AWS Lambda. As of now, Lambda supports Node.js 16.x and 18.x. Consider downgrading your Node.js version to one of these supported versions.
-
Review your dependencies: The error stack trace mentions @aws-sdk modules. Make sure you're using versions of these SDK modules that are compatible with the Lambda runtime you're using.
-
Check for undefined objects: Look through your code, particularly in the files mentioned in the stack trace (utils.js, postgresDB.js), for any instances where you might be trying to define properties on potentially undefined objects.
-
Transpile your code: If you're using newer ECMAScript features, consider transpiling your code to an earlier version of JavaScript that's more widely supported.
-
Test locally: Try to replicate the Lambda environment locally and test your code there. This can help identify issues before deployment.
-
Review your build process: Ensure your build process (if any) is correctly bundling all necessary dependencies and not introducing any issues.
If the problem persists after trying these steps, you may need to do a more detailed code review or consider reaching out to AWS support for further assistance.
Sources
AWS lambda function gets crash and throws below error. But working fine in my local environment | AWS re:Post
ReferenceError with lambda function : "errorMessage": "require is not defined in ES module scope | AWS re:Post
Hi, this is happening all the way, please upvote this and check:
I have this issue as well and nothing helps.
I have seen this same error with node version 18 and the stack trace pointing to : node_modules/@aws-sdk/client-eventbridge/dist-cjs/auth/httpAuthSchemeProvider.js . Setting the version of "@aws-sdk/client-eventbridge" to "3.703.0" helped resolve this error. The latest versions 3.744, 3.734 etc throw this same TypeError.

I have already seen this. nothings helps in my case.