-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 redefine property: handle when run as AWS lambda #2199
Comments
I can't reproduce this by bundling that code with those options. This isn't surprising because the code you provided just exports something without using it. I assume you also have some additional code that is trying to import require('./bundle/index.js').handle = something; That won't work because the Another potential resolution is to investigate what is attempting to mutate the |
So when writing for lambda you expose a function, but don't actually use it in your code. When you deploy the compiled js to lambda aws calls it upon the lambda being triggered. Nothing in my code (outside of tests) calls the method and nothing mutates the export. |
Ah, ok. Sorry I am not familiar with AWS Lambda. Maybe the problem is in AWS Lambda itself then? Does the stack trace that you get perhaps provide more information? What does it look like? Edit: Adding the |
Here is the error I get:
I'm not sure why but for some reason it seems to export twice in esbuild (although this could be my lack of esbuild knowledge) // src/index.ts
var src_exports = {};
__export(src_exports, {
handle: () => handle
});
// ...
0 && (module.exports = {
handle
}); A similar function compiled using tsc: Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
//...
async function handler(event) {
//...
}
exports.handler = handler; |
AWS lambda seems to use shimmer which uses Currently you can only use cjs style exports directly ( There was a same request before #1079. |
Thanks for the explanation on cjs :) I assume by the fact that it's been open for a while that feature isn't going to be implemented so I should just continue to use exports.handle or speak with aws about the use of shimmer? |
Yes, this is unlikely to be implemented. I recommend just using Closing this issue as "by design." |
Hi there,
I'm trying to use esbuild to bundle my typescript project to be used by aws lambda. I'm not sure what else to try, but I cannot get it to successfully pass while using es6 exports in my code.
My code looks something like:
My esbuild.config.js looks something like this:
and my ts config looks like this:
The only way I can get this to work is instead of using
export const handle
/export default { handle }
. I useexports.handle = handle
. Any help would be greatly appreciatedThe text was updated successfully, but these errors were encountered: