Error encountered while bundling CDK Synth with Node.js function - Kindly ensure to update your lock file by running `npm install` before proceeding further

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:

  1. I successfully installed all node-modules by navigating into the Lambda folder and executing "npm install". No errors appeared in the terminal.
  2. I added necessary packages to the bundling.nodeModules in the NodejsFunction function properties.
  3. Ensured that
    "type": "module"
    was correctly set inside the package.json file.
  4. Stripped down the Lambda-handler code to just the basic structure of
    export async function handler(event: any, context: object) {}
    , yet the error persist.

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

  1. Uninstalling all node-modules and installing any single package triggers the error consistently, indicating it's not specific to a particular package.
  2. Refer to this documentation for insights on the NodejsFunction.

Answer №1

In order to resolve this issue, you can address the error by including the depsLockFilePath parameter within the props of the new NodejsFunction:

depsLockFilePath: join(__dirname, "../src/lambda-handlers/lambdaFunction/package-lock.json"),

For further details on this solution, refer to the documentation provided here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method for retrieving properties from a generic in typescript?

In my code snippet, I am dealing with a generic type variable called data and I am looking for a way to access the values of its properties. The method hasOwnProperty isn't effective in this case due to the generic nature of the data. const data: T = ...

Setting up Webpack for my typescript React project using Webpack Version 4.39.2

I have been given the task of fixing the Webpack build in a project that I am currently working on. Despite not being an expert in Webpack, I am facing difficulties trying to make it work. The project has an unconventional react frontend with typescript. I ...

Decompress a 7z archive stored on an AWS S3 bucket using a node

Does anyone have a recommendation for an npm package that can extract 7z files in node.js? I've come across some npm packages for ZIP files, but none seem to work for 7Z files. My specific goal is to extract a password-protected 7z file from S3 and ...

React Native dependency issue causing installation problem

Just diving into the world of React Native, I decided to streamline my UI design by installing @shoutem/ui. However, after installation, I encountered a dependency error when running my application: https://i.sstatic.net/26CSs.png I then proceeded to ins ...

Is there a specific type that is narrower in scope when based on a string parameter?

tgmlDoc.createElement(tagName) typically returns objects of type any. I am looking to refine the return type in the function below in order to simplify the rest of my code. Is there a way to accomplish this? My attempt is shown below, but unfortunately, ...

Transitioning to TypeScript: Why won't my function get identified?

I am in the process of transitioning a functional JavaScript project to TypeScript. The project incorporates nightwatch.js Below is my primary test class: declare function require(path: string): any; import * as dotenv from "dotenv"; import signinPage = ...

Methods for transforming a TypeScript class instance containing getter/setter properties into a JSON format for storage within a MySQL database

I am currently working on a TypeScript class that includes a getter and setter method: export class KitSection { uid: string; order: number; set layout(layout: KitLayout) { this._layout = new KitLayout(layout); } get layout( ...

The command "tsc" was not found in this bash session

Currently, I am using a MAC and attempting to set up TypeScript. I followed the installation process by running sudo npm install -g typescript and received the following output: Password: /Users/<myuserid>/node/bin/tsc -> /Users/<myuserid& ...

Tips for customizing Material UI's styled() SVG icon to accept SVG icon as a react component:

Currently, I have functioning code that uses the "any" type for props. When transitioning to MUI v5 and using the mui v4 makeStyles, this approach raises compatibility issues that were not present before. // Import SVG Icons components import { ReactCo ...

msal npm build execution halted due to loader issues

I've been working on setting up msal for use with nodejs. My goal is to verify that emails are successfully received by test users in end-to-end webdriverio tests. Following the npm msal guide here, I made good progress but ran into some errors while ...

I seem to be invisible to the toggle switch

I currently have a toggle button that controls the activation or deactivation of a tooltip within a table. Right now, the tooltip is activated by default when the application starts, but I want to change this so that it is deactivated upon startup and on ...

Can parameters with identical union types in a function signature be streamlined to contain only the exact same subtypes using generic types?

// defining a type Combinable with string or number as possible values type Combinable = string | number; // function to check if parameter is a string function isString(param: unknown): param is string { return typeof param === "string"; } /** * Func ...

Is it possible to assign default values to optional properties in JavaScript?

Here is an example to consider: interface Parameters { label: string; quantity?: number; } const defaultSettings = { label: 'Example', quantity: 10, }; function setup({ label, quantity }: Parameters = { ...defaultSettings }) { ...

What steps should I take to create a React component in Typescript that mimics the functionality of a traditional "if" statement?

I created a basic <If /> function component with React: import React, { ReactElement } from "react"; interface Props { condition: boolean; comment?: any; } export function If(props: React.PropsWithChildren<Props>): ReactElement | nul ...

Navigating Peer Dependency Conflicts in React Native: What to Do When a Library Requires a Higher Version Than Expected

I have encountered a dependency issue while using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="acdec9cdcfd881c2cdd8c5dac9ec9c829a98829f">[email protected]</a> with the package <a href="/cdn-cgi/l/email-protec ...

Issue with the google-api-nodejs-client

Encountering a similar issue to the one discussed in this question: Can't find module googleapis I attempted to follow the solution provided by Max, but upon running npm run build, I encountered the following: npm i typescript -g npm run build An ...

The entry for package "ts-retry" could not be resolved due to possible errors in the main/module/exports specified in its package.json file

I encountered an error while attempting to run my React application using Vite. The issue arises from a package I am utilizing from a private npm registry (@ats/graphql), which has a dependency on the package ts-retry. Any assistance in resolving this pro ...

What is the best approach to implementing a blur function for a specific input within a parent component?

I have created a custom input field as a separate component. I want to include multiple input fields in the parent component using directives: <app-input ...></app-input> My goal is to pass the blur event/function to the parent component speci ...

The correct way to incorporate a global property into a component template (using Vue 3, Vite, TypeScript, and the Composition API)

The component's property is not functioning properly https://i.sstatic.net/qaUG9.png src/main.ts import { createApp } from 'vue' import languagePlugin from '@/plugins/languagePlugin' import App from './App.vue' const a ...

The parameter type cannot be assigned an undefined argument

I am new to TypeScript and trying to check if an item already exists. However, when I define the previous variable, I'm encountering an error: "Argument of type '(prev: CartItemsType[]) => CartItemsType[] | undefined' is not assignable to ...