dockernpmaws-sam

"npm ci"/"npm install" in AWS/SAM build fails with Node 18 but succeeds with 14


I'm trying to upgrade a project from Node v14 to v18.

TLDR: npm ci --omit=dev fails in sam-build with node-v18, but succeeds locally or in sam-build node v14.

I used to build a simple image for AWS/SAM using sam build --use-container --debug --config-env staging (arch x86_64), with Dockerfile

FROM public.ecr.aws/lambda/nodejs:14
RUN yum -y install make gcc-c++ python3
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --omit=dev
...

which works fine. But when I try to use Node 18 (public.ecr.aws/lambda/nodejs:18), sam-build fails with Error: The command '/bin/sh -c npm ci --omit=dev' returned a non-zero code: 254.

Even with sam build --debug there is no additional output related to the npm ci-command.

Running the npm ci-command locally or building the image using docker command docker build -t testAbc --platform linux/amd64 -f Dockerfile . both succeed.

All these attempts result in same error (code 254):

Do you know a way on either


Solution

  • The git package was missing:

    RUN yum -y install make gcc-c++ python3 git
    

    When upgrading from public.ecr.aws/lambda/nodejs:14 to public.ecr.aws/lambda/nodejs:18, python3 became a required package (for my node-dependencies anyways). I guess, I must have accidentally removed git 😓