Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patch Package with Docker

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

like image 908
donjus Avatar asked Apr 28 '26 11:04

donjus


1 Answers

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
like image 197
blimmer Avatar answered May 01 '26 00:05

blimmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!