This is an old thread, but it may still help some people. The answer is you don't use NPM in your final container image.
For example, with Docker multistage build it will be something like that
# Build stage
FROM node:16-alpine3.15 as build
# Install dependencies
WORKDIR /
COPY package-lock.json .
COPY package.json .
RUN npm ci --production
# Final stage
FROM alpine:3.15 as final
# Upgrade APK
RUN apk --no-cache add --upgrade nodejs~16
# Setup application
RUN mkdir -p /app/simple-server
WORKDIR /app/simple-server
COPY . .
COPY --from=build node_modules node_modules
# Run App
ENTRYPOINT ["node", "index.js"]
You can see the final image doesn't have NPM, which is still vulnerable to CVE-2021-3807.