0

我正在使用节点 js 后端,我想通过 docker 部署应用程序。

我更改了两个 npm 包以使我的应用程序正常工作,并在我的 package.json 中的安装后脚本的帮助下使用 npm patch-package 自动安装这些更改。

 "postinstall": "patch-package"

我将 postinstall-postinstall 和 patch-package 都安装为开发依赖项。

分别运行 yarn install 和 yarn build 可以正常工作,但是一旦我想 dockerize 这个应用程序,我在构建阶段就会收到一个错误,这基本上是说补丁没有应用到 node_modules。

这是我的码头文件:

# 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

我真的不知道 dockerfile 中的 yarn install 脚本是否没有在安装后运行,或者错误是否只发生在 yarn build 脚本中。

提前致谢

4

1 回答 1

0

正如@donjus 在评论中提到的那样,补丁被复制到根目录,而不是patches.

解决方法是改变:

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

COPY package.json yarn.lock ./
COPY ./patches ./patches
RUN yarn install --frozen-lockfile --unsafe-perm
于 2022-03-03T17:59:37.910 回答