(aws-lamdba-nodejs): esbuild + yarn berry monorepo + bundling.nodeModules fails in CI #17082
Labels
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p1
package/tools
Related to AWS CDK Tools or CLI
What is the problem?
When using a
yarn
monorepo layout (as described in the Reference Architecture), an issue occurs on CI platforms whenesbuild
tries to bundle the lambda function.Upon bundling an error like this appears:
The problem is because
yarn
automatically goes into "immutable" mode on CI platforms (see https://github.com/yarnpkg/berry/blob/dd043a8ab1618c0b02e28b2b40743bd336d63437/packages/plugin-essentials/sources/index.ts#L88-L92).Then, when bundling, the monorepo's
yarn.lock
file gets copied into the bundling temporary directory:The
package.json
file contains thenodeModules
I've specified in thebundlingProps
. For instance, this construct instantiation:produces this
package.json
file in the bundling directoryHerein lies the problem. The
yarn.lock
file is out of sync for this limitedpackage.json
file because it contains all the dependencies for the entire monorepo. And, becauseyarn
automatically goes intoimmutable
mode on CI platforms, the bundling (when it runsyarn install
) fails.Reproduction Steps
bug/yarn-lockfile-in-ci
branch)git clone https://github.com/blimmer/cdk-bug-reports.git --branch=bug/yarn-lockfile-in-ci
yarn install
).export YARN_ENABLE_IMMUTABLE_INSTALLS=true
). This happens automatically in CI environments, but you can simulate it locally.cd packages/pkg1
. this is the workspace with aNodejsFunction
that specifies abundling.nodeModules
package.yarn cdk synth
.You'll observe the lockfile error.
esbuild
will print the bundling temporary directory where you can see the state described in the section above.Alternatively, you can check out the failure in GitHub actions here: https://github.com/blimmer/cdk-bug-reports/runs/3956431715. github actions log output - just in case GitHub logs time out for https://github.com/blimmer/cdk-bug-reports/runs/3956431715
What did you expect to happen?
Because I followed the Reference Architecture for monorepos, I expected bundling in my CI environment to work without throwing an error.
What actually happened?
I received an error during bundling that the lockfile would be changed, so my NodejsFunction failed to
synth
.github actions log output - just in case GitHub logs time out for https://github.com/blimmer/cdk-bug-reports/runs/3956431715
CDK CLI Version
1.128.0 (build 1d3883a)
Framework Version
No response
Node.js Version
14.x
OS
macos, github actions CI (linux)
Language
Typescript
Language Version
TypeScript 3.9.10 | Yarn Berry v3 | Esbuild 0.13.x
Other information
Proposed Solution
I think the easiest way to fix this would be to flag
yarn
to not use immutability when bundling localbundling.nodeModules
-specified dependencies:That would avoid this issue automatically for all users. There's more details on this flag here.
Workaround
In case you find this bug report and you need to work around this issue, you can set this environment variable in your CI platform before running
cdk synth
orcdk deploy
:I recommend only setting this before the
cdk synth
orcdk deploy
command so when you're installing your project dependencies, immutability is still respected.The text was updated successfully, but these errors were encountered: