0

I'm working with a node js backend and I want to deploy the application via docker.

I changed two npm packages to get my application working and automatically install these changes with npm patch-package with the help of a post install script in my package.json.

 "postinstall": "patch-package"

I installed both both postinstall-postinstall and patch-package as dev dependencies.

Running yarn install and yarn build seperatly this works fine but once I want to dockerize this application I get an error during the build phase, which basically says that the patch wasn't applied to the node_modules.

This is my dockerfile:

# stage 1
FROM node as builder
WORKDIR /srv
COPY package.json yarn.lock patches ./
RUN yarn install --frozen-lockfile --unsafe-perm
COPY . .
RUN yarn build

I don't really know if the yarn install script in the dockerfile is not running post install or if the error only happens in the yarn build script.

Thanks in advance

2
  • Can you confirm if the patch file is being successfully copied into your container where you want it to be? May 28, 2021 at 10:56
  • Found my error. I copied the patches directory into the root directory of the docker image and not into a separate patches directory
    – donjus
    May 28, 2021 at 11:09

1 Answer 1

2

As @donjus mentioned in the comments, the patches were being copied to the root directory, not inside of patches.

The solution is to change:

COPY package.json yarn.lock patches ./
RUN yarn install --frozen-lockfile --unsafe-perm

to

COPY package.json yarn.lock ./
COPY ./patches ./patches
RUN yarn install --frozen-lockfile --unsafe-perm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.