Describe the bug
When bundling a lambda function using lambda_nodejs with no dependencies and with pnpm version 8.4.0 or higher, the script fails to delete the node_modules/.modules.yaml file.
Expected Behavior
The bundling succeeds (no need to delete this file).
Current Behavior
The bundling fails with error :
Bundling asset stack/lambda-fn/Code/Stage...
...dk.out/bundling-temp-d1f50916a16a3a6ba493bb8442e9fc9680e83df6b64d7a5183903277f0923fc7/index.js 2.1kb
⚡ Done in 8ms
Already up to date
Done in 314ms
rm: [..]/cdk.out/bundling-temp-d1f50916a16a3a6ba493bb8442e9fc9680e83df6b64d7a5183903277f0923fc7/node_modules/.modules.yaml: No such file or directory
...
Error: Failed to bundle asset stack/lambda-fn/Code/Stage, bundle output is located at [...] exited with status 1
Reproduction Steps
Simple lambda construct :
new lambda.NodejsFunction(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
entry: path.join(__dirname, 'lambda', 'src/index.ts'),
});
/lambda/package.json
{
"dependencies": {
"aws-lambda": "^1.0.7"
},
}
/lambda/src/index.ts
import { DefineAuthChallengeTriggerHandler } from 'aws-lambda';
export const handler: DefineAuthChallengeTriggerHandler = async (event) => {
return event;
};
/package.json
{
"dependencies": {
"aws-cdk": "^2.70.0",
"aws-cdk-lib": "2.67.0",
"constructs": "^10.0.0",
},
"devDependencies": {
"esbuild": "^0.17.11",
"ts-node": "^10.0.0",
"typescript": "4.9.5"
}
}
pnpm version :
v8.4.0 -> bundling fails
- below
v8.4.0 -> bundling succeeds
Possible Solution
In the bundling.ts source file :
- add
-f flag to the rm command
- don't perform the
rm command if pnpm -v >= 8.4.0
Additional Information/Context
The pnpm v8.0.4 release note specifies clearly :
Do not create a node_modules folder with a .modules.yaml file if there are no dependencies inside node_modules.
Since esbuild bundles the dependencies (unless specified otherwise through lambda_nodejs.NodejsFunctionProps['bundling]['nodeModules']), this will break synthesis of most lambda functions.
CDK CLI Version
2.70.0 (build c13a0f1)
Framework Version
No response
Node.js Version
v16.19.1
OS
macOs 13.3.1 (22E261)
Language
Typescript
Language Version
Typescript (4.9.5)
Other information
Source file is located at packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts
Describe the bug
When bundling a lambda function using
lambda_nodejswith no dependencies and withpnpmversion8.4.0or higher, the script fails to delete thenode_modules/.modules.yamlfile.Expected Behavior
The bundling succeeds (no need to delete this file).
Current Behavior
The bundling fails with error :
Reproduction Steps
Simple lambda construct :
/lambda/package.json{ "dependencies": { "aws-lambda": "^1.0.7" }, }/lambda/src/index.ts/package.json{ "dependencies": { "aws-cdk": "^2.70.0", "aws-cdk-lib": "2.67.0", "constructs": "^10.0.0", }, "devDependencies": { "esbuild": "^0.17.11", "ts-node": "^10.0.0", "typescript": "4.9.5" } }pnpmversion :v8.4.0-> bundling failsv8.4.0-> bundling succeedsPossible Solution
In the
bundling.tssource file :-fflag to thermcommandrmcommand ifpnpm -v>=8.4.0Additional Information/Context
The
pnpmv8.0.4 release note specifies clearly :Since
esbuildbundles the dependencies (unless specified otherwise throughlambda_nodejs.NodejsFunctionProps['bundling]['nodeModules']), this will break synthesis of most lambda functions.CDK CLI Version
2.70.0 (build c13a0f1)Framework Version
No response
Node.js Version
v16.19.1OS
macOs 13.3.1 (22E261)
Language
Typescript
Language Version
Typescript (4.9.5)
Other information
Source file is located at
packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts