-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
❗ NOTICE (aws-lambda-nodejs): Runtime.ImportModuleError: Cannot find module 'module'
#30717
❗ NOTICE (aws-lambda-nodejs): Runtime.ImportModuleError: Cannot find module 'module'
#30717
Comments
The temporary solution to this is to pin the version of esbuild to |
The README section on modules will also need to be updated to reflect the change in default behaviour |
We made the following change and that fixed the issue Issue reported on
|
Another temporary solution is to add the now required parameter instead of specifying the version. This will keep the old bundling functionality working with the new esbuild version. In JS/TS this would look somewhat like this: new NodejsFunction(scope, "my-esbuild-lambda", {
functionName: "awesome-function",
...
bundling: {
esbuildArgs: {
"--packages": "bundle",
},
},
}) |
Everyone looking for a temporary fix, I recommend doing this until we have settled on a solution in CDK:
|
@tobiberger solution worked for me. <3 |
As there are already some people liking my proposed solution, here's something for your consideration: One more thing you should know is that setting the esbuild version in cdk code only works when using docker for bundling. This is the default, so it should work for most people. However, if your cdk project is running in a node environment where esbuild is already installed and you haven't specified the Edit: I just realized that the fact about using the esbuild version present in a node project can be very useful for large projects, as it provides the opportunity to set the esbuild version for the whole project in one place instead of setting it in every NodejsFunction constructor. |
Hey, aws guys. This is really a critical issue. I have a huge CDK project and I cannot add |
We are currently in the process of creating a patch release with the esbuild version pinned to |
Cannot find module 'module'
Thank you for the balanced write-up @tobiberger ! My main concern right now is that $ touch index.js
$ npx esbuild@0.21.x index.js --packages=bundle
✘ [ERROR] Invalid value "bundle" in "--packages=bundle"
The only valid value is "external".
1 error |
my workaround for Lambdas functions was to pin the version of esbuild in the NodeJsFunction this.lambda = new NodejsFunction(this,
StateApi, {
....
bundling: {
esbuildVersion: "0.21.0",
}
}); |
…rror (#30726) ### Issue # (if applicable) Closes #30717. ### Reason for this change esbuild introduced a breaking change in v0.22 which caused the build error in `aws-lambda-nodejs` module. ### Description of changes Pin the esbuild version to 0.21 in Dockerfile ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Update notice for aws/aws-cdk#30717
I am not sure if this issue should be marked a closed. |
The closure happened automatically because the linked PR was merged. I'm not sure, however, if we will be able to support a touch-free upgrade to 0.22. We cannot update the default to include |
Thanks for re-opening the issue @TheRealAmazonKendra. |
|
Esbuild released a new version that reverts the change (0.23), so that it now behaves the same as pre-0.22. Despite all this, I think CDK should consider pinning to a known working version at least in the docker-based build. |
I would also like to share some of my expectations and opinions on this matter.
Absolutely agree. ESBuild doesn't follow semantic versioning and uses minor versions for breaking changes, as stated by the maintainer in #3817:
In the release notes of 0.23 he also strongly advocates on pinning the version:
However, I would also like to point out that any build dependencies have to be pinned to expected versions, in order to avoid any unexpected system outages like we had this time. There's nothing worse, than having a version deployed to a dev/staging system that works and deploying the same version without changes a day later to production and having an outage 😕. For example, I saw this line in the Docker build logs, which suggests that TypeScript is also not pinned to any version (not even a major version): RUN npm install --global typescript Maybe other dependencies are affected as well, so it would be great, if you could check this.
As long as the build/stack synth fails, I'm personally fine with this, as long as there's an expressive error message telling me what to do. For me it's much more preferable to see a build time error and a broken pipeline, than an unexpected runtime error in a production system 😉. |
Another comment. a) NodejsFunction is cool. Therefore, why not just buy ESBUILD, or create your own, and roll it into CDK CLI? Also, the more AWS controls the code, the more it can control the DevSecOps pipeline, the (hopefully) more reliable the CDK, and the minimisation of these 3rd party derived issues. Right? |
I bumped to the latest aws-cdk version 2.148.0 and was still seeing the problem. I realized it is because I also had For those unaware, you can install esbuild (eg. So, if you've bumped cdk and are still seeing this issue, you might have esbuild in your package.json. You'll need to install the esbuild@0.23.0 and it should be pinned to the version.
|
Docker bundling will run a docker build ever time you run it. If the layers aren't already built on the machine, this means installing yarn, pnpm, typescript, and esbuild. That might be where the performance difference comes from. |
Closing this issue because the error has been mitigated. We will create a separate Github issue to pin the version to prevent this happening in the future. |
Comments on closed issues and PRs are hard for our team to see. |
Please add your +1 👍 to let us know you have encountered this
Status: RESOLVED
Fixed in v2.147.3.
Overview:
With the v0.22 release of esbuild, the default bundling behavior has been changed to omit imported packages from the bundle by default when the platform is node. The recommendation is to set the
packages
option tobundle
to get the desired bundling behavior.Complete Error Message:
Workaround:
We recommend pinning the version to
0.2.15
Note: You may also add the flag
--packages=bundle
but this may result in other errors and is not recommended.Solution:
We have pinned the version of esbuild used when no version is already installed to
0.2.15
.Original Issue Content:
Expected Behavior
When executing the lambda,
import package from 'somePackage'
imports the target packageCurrent Behavior
When executing the lambda,
import package from 'somePackage'
throws aRuntime.ImportModuleError
with messageCannot find module 'somePackage'
Reproduction Steps
Possible Solution
Add
--packages=bundle
to the default esbuildCommand created. Tried this on the reproduction lambda but seems to error withMust use "outdir" when there are multiple input files
. I'm not familiar enough with esbuild to understand why this is happening and how to fix it.Additional Information/Context
No response
CDK CLI Version
2.147.2
Framework Version
2.147.2
Node.js Version
18.17.1
OS
Ubuntu 22.04.4 LTS
Language
TypeScript
Language Version
5.5.2
Other information
No response
The text was updated successfully, but these errors were encountered: