Patch Package with Docker

2.5k views Asked by At

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

1

There are 1 answers

0
blimmer On

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