Skip to content

Bug: jmespath custom functions introspection breaks when minifying #2383

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

Closed
dreamorosi opened this issue Apr 17, 2024 · 2 comments · Fixed by #2384
Closed

Bug: jmespath custom functions introspection breaks when minifying #2383

dreamorosi opened this issue Apr 17, 2024 · 2 comments · Fixed by #2384
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped jmespath This item relates to the JMESPath Utility

Comments

@dreamorosi
Copy link
Contributor

Expected Behaviour

When using the JMESPath utility I should be able to minify my code and all the utility's features should work.

Current Behaviour

When the function including the utility is minified the utility is not able to introspect its own methods and correctly register the functions available, which causes a runtime error:

2024-04-17T08:03:11.119Z        a71a8744-df90-4187-bff6-d8f8e0d0478d    ERROR   Invoke Error    {"errorType":"TypeError","errorMessage":"t.introspectMethods is not a function or its return value is not iterable","stack":["TypeError: t.introspectMethods is not a function or its return value is not iterable","    at Object.introspectMethods (/var/task/index.js:2:12877)","    at l.introspectMethods (/var/task/index.js:2:12877)","    at U.introspectMethods (/var/task/index.js:2:12877)","    at new ue (/var/task/index.js:2:16337)","    at he.search (/var/task/index.js:2:20094)","    at Le (/var/task/index.js:2:30000)","    at Runtime.Sr [as handler] (/var/task/index.js:2:31173)","    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"]}

This affects both ESM and CJS builds and can be mitigated only by not aliasing functions/methods names in the minified bundle - in esbuild this corresponds to the keepNames field.

Code snippet

import { search } from "@aws-lambda-powertools/jmespath";
import { PowertoolsFunctions } from "@aws-lambda-powertools/jmespath/functions";

export const handler = async (event: any): Promise<any> => {
  return search("powertools_json(foo).bar", event, {
    customFunctions: new PowertoolsFunctions(),
  });
};

Steps to Reproduce

Bundle the function above and minify it:

npx esbuild --bundle index.ts --platform=node --outdir=out --format=esm --minify

Then deploy and observe the error.

On the other hand, if you also enable the --keepNames flag, the error won't occur.

Possible Solution

Refactor this method used to register the available methods to not rely on the prototype, or statically define the methods beforehand if that's not possible.

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

Lambda Layers, npm

Execution logs

No response

@dreamorosi dreamorosi added bug Something isn't working confirmed The scope is clear, ready for implementation jmespath This item relates to the JMESPath Utility labels Apr 17, 2024
@dreamorosi dreamorosi self-assigned this Apr 17, 2024
@dreamorosi dreamorosi moved this from Triage to Working on it in Powertools for AWS Lambda (TypeScript) Apr 17, 2024
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Apr 17, 2024
@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Apr 17, 2024
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

Copy link
Contributor

This is now released under v2.1.0 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Apr 18, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped jmespath This item relates to the JMESPath Utility
Projects
1 participant