Skip to content
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

NodejsFunction: External dependecy bundling not working? #26464

Closed
rupe120 opened this issue Jul 21, 2023 · 6 comments
Closed

NodejsFunction: External dependecy bundling not working? #26464

rupe120 opened this issue Jul 21, 2023 · 6 comments
Labels

Comments

@rupe120
Copy link

rupe120 commented Jul 21, 2023

Describe the bug

I install a module and reference it in bundling.externalModules[] and the execution fails with a Module Not Found error

Expected Behavior

Successfully import external module

Current Behavior

With uuid both installed and referenced in bundling.externalModules[], the following error is produced.

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'uuid'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'uuid'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:997:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1029:21)",
        "    at async start (file:///var/runtime/index.mjs:1192:23)",
        "    at async file:///var/runtime/index.mjs:1198:1"
    ]
}

Reproduction Steps

Deploy the following app and run the Lambda.

https://github.com/rupe120/cdk-typescript-bundling-dependency-test

Possible Solution

Unknown

Additional Information/Context

No response

CDK CLI Version

2.88.0

Framework Version

No response

Node.js Version

v18.16.1

OS

Windows 11 Enterprise build 22621.1702

Language

Typescript

Language Version

Typescript 5.1.6

Other information

No response

@rupe120 rupe120 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2023
@tmokmss
Copy link
Contributor

tmokmss commented Jul 21, 2023

You should be able to use nodeModules instead of externalModules to make the package available on runtime environment without bundling it.

@jsec
Copy link

jsec commented Jul 21, 2023

externalModules actually does the opposite of what you're expecting. It's a list of modules that esbuild will not bundle with your function, because they're considered external modules that are already available in the runtime (ie. @aws-sdk/*). So in this case, you wouldn't want to add uuid to externalModules, so that it's available to your lambda's runtime.

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Jul 21, 2023
@peterwoodworth
Copy link
Contributor

Thanks for the help offered, does this help unblock @rupe120?

@peterwoodworth peterwoodworth added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 21, 2023
@rupe120
Copy link
Author

rupe120 commented Jul 22, 2023

Thanks for the help offered, does this help unblock @rupe120?

I haven't tried it yet but I think this will resolve my issue.

I do feel like the description should be updated to reference the difference between the 2 properties.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 22, 2023
@rupe120
Copy link
Author

rupe120 commented Jul 22, 2023

Yes, not listing the desired module in externalModules solved my issue.

@rupe120 rupe120 closed this as completed Jul 22, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants