Skip to content

errorType": "TypeError" "errorMessage": "Object.defineProperty called on non-object"

0

I was having my node version as 20 before and now but for the past two days when i try to deploy there's a error thrown by lambda, I dont know what causes the issue here

2025-01-07T07:28:45.434Z undefined ERROR Uncaught Exception { "errorType": "TypeError", "errorMessage": "Object.defineProperty called on non-object", "stack": [ "TypeError: Object.defineProperty called on non-object", " at defineProperty ()", " at __name (/var/task/dist/index.js:157789:37)", " at <static_initializer> (/var/task/dist/index.js:157981:9)", " at node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js (/var/task/dist/index.js:157976:34)", " at __require (/var/task/dist/index.js:13:51)", " at node_modules/@aws-sdk/client-s3/dist-cjs/index.js (/var/task/dist/index.js:160360:37)", " at __require (/var/task/dist/index.js:13:51)", " at dist/src/lib/utils.js (/var/task/dist/index.js:173703:23)", " at __require (/var/task/dist/index.js:13:51)", " at dist/src/lib/postgresDB.js (/var/task/dist/index.js:190259:19)" ] }

asked a year ago2K views
3 Answers
1

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. Test locally: Try to replicate the Lambda environment locally and test your code there. This can help identify issues before deployment.

  6. 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

answered a year ago
0

Hi, this is happening all the way, please upvote this and check:

https://stackoverflow.com/questions/79339640/errortype-typeerror-errormessage-object-defineproperty-called-on-non-ob?newreg=65d4bcf5a0154b8db321e92a067eab31

I have this issue as well and nothing helps.

answered a year ago
  • I have already seen this. nothings helps in my case.

0

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.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.