As I attempt to utilize AWS CDK for creating a Lambda function, I am facing a challenging error:
"npm ERR! npm ci
can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install
before continuing."
This leads to errors stating "Missing: [PACKAGE NAME] from lock file" for all required packages.
Directory Structure of Lambda Function:
- helpers
- node_modules
- index.ts
- LambdaFunction.test.ts
- package.json
- package-lock.json
Steps Taken:
- I successfully installed all
node-modules
by navigating into the Lambda folder and executing "npm install". No errors appeared in the terminal. - I added necessary packages to the
bundling.nodeModules
in theNodejsFunction
function properties. - Ensured that
was correctly set inside the"type": "module"
package.json
file. - Stripped down the Lambda-handler code to just the basic structure of
, yet the error persist.export async function handler(event: any, context: object) {}
Code Snippet for Stack Creation:
const lambdaFunction = new NodejsFunction(this, `intoNSQueueConsumer`, {
...defaultProps,
description: "description",
entry: join(__dirname, "../src/lambda-handlers/lambdaFunction/index.ts"),
environment: {
ENVIRONMENT: context.environment,
},
bundling: {
nodeModules: ["axios", "axios-retry", "crypto-js"], // Need to be installed
externalModules: ["aws-sdk"], //already available in the runtime
},
});
UPDATE
- Uninstalling all node-modules and installing any single package triggers the error consistently, indicating it's not specific to a particular package.
- Refer to this documentation for insights on the
NodejsFunction
.