Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"TypeError: Object.defineProperty called on non-object" with versions newer than 3.722.0 #7021

Answered by zshzbh
crispy101 asked this question in Q&A
Discussion options

Hello,

I'm getting an Object.defineProperty called on non-object error when using any versions newer than 3.722.0 for my Lambda@Edge function. The full stack trace is:

 "TypeError: Object.defineProperty called on non-object",
 " at defineProperty (<anonymous>)",
 " at __name (/var/task/origin-response.js:40:19710)",
 " at <static_initializer> (/var/task/origin-response.js:40:26354)",
 " at node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js (/var/task/origin-response.js:40:26300)",
 " at /var/task/origin-response.js:1:554",
 " at node_modules/@aws-sdk/client-s3/dist-cjs/index.js (/var/task/origin-response.js:58:70715)",
 " at /var/task/origin-response.js:1:554",
 " at Object.<anonymous> (/var/task/origin-response.js:58:426696)",
 " at Module._compile (node:internal/modules/cjs/loader:1364:14)",
 " at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)"

There doesn't seem any obviously relevant change on the next release, i.e. 3.723.0, hece posting this issue here.

A slightly simplified version of the code looks like this - it reads a file from a bucket and use the cotent as a custom response header value:

import { CloudFrontResponseEvent, CloudFrontResponse } from "aws-lambda";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
 region: process.env.BUCKET_REGION,
});
const OBJECT = process.env.OBJECT;
const S3_BUCKET = process.env.S3_BUCKET;
export const handler = async (
 event: CloudFrontResponseEvent
): Promise<CloudFrontResponse> => {
 const response = event.Records[0].cf.response;
 response.headers = response.headers || {};
 let result = "";
 }
 try {
 const params = { Bucket: S3_BUCKET, Key: OBJECT };
 const s3Object = await s3.send(new GetObjectCommand(params));
 if (!s3Object.Body) {
 throw new Error("The file is empty or missing");
 }
 result += s3Object.Body.toString();
 console.log("the file retrieved:", result);
 response.headers["x-custom-header"] = [
 { key: "X-Custom-Header", value: result },
 ];
 } catch (error) {
 console.error("Error fetching the file or adding header:", error);
 throw error;
 }
 return response;
};

Again, the same code works well if 3.722.0(or older) is used. Tested on the runtime Node v20 and 18, too, and no difference.

Can anyone shed some light on this.

You must be logged in to vote

Hey @crispy101 ,

I just found 2 resolved issues that might be related to this issue. What is your esbuild version? Have you tried to update esbuild version? It sounds like a version mismatch since it works fine with 3.722.0

#6991
#6926

Replies: 1 comment 1 reply

Comment options

Hey @crispy101 ,

I just found 2 resolved issues that might be related to this issue. What is your esbuild version? Have you tried to update esbuild version? It sounds like a version mismatch since it works fine with 3.722.0

#6991
#6926

You must be logged in to vote
1 reply
Comment options

Hi @zshzbh,

Wonderful! Yes that was the issue. Bumping up esbuild from 0.17 to 0.18 has resolved the issue.
Thanks very much!

Answer selected by crispy101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
duplicate This issue is a duplicate.
2 participants

AltStyle によって変換されたページ (->オリジナル) /