在本地运行
npm install
时,一切都很好,但是当我在 docker 容器中尝试它时,我收到以下错误:
/api/node_modules/sharp/lib/constructor.js:1
Something went wrong installing the "sharp" module
Error relocating /api/node_modules/sharp/build/Release/../../vendor/8.10.6/lib/libvips-cpp.so.42: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev: symbol not found
任何帮助非常赞赏!
Docker 镜像非常简单:
FROM node:12.13.0-alpine AS alpine
WORKDIR /api
COPY package.json .
RUN npm install
就我而言,在通过搜索 Sharp 的 github 问题尝试了很多不同的选项后,将此行添加到我的 Dockerfile 中修复了它:
RUN npm config set unsafe-perm true
如果您使用的是节点:15 或更高版本,
--unsafe-perm
已被删除,这是一个解决方法:
...
RUN chown root.root . # make sure root own the directory before installing Sharp
RUN npm install
我遇到了问题,因为使用 Docker 我正在复制本地节点模块,这些模块与 docker 中的 Linux 环境不兼容。如果您在 docker 容器中使用 Sharp 包时遇到问题,请检查此项。