繁体   English   中英

linux-x64 二进制文件无法在 linuxmusl-x64 平台上使用错误

[英]linux-x64 binaries cannot be used on the linuxmusl-x64 platform error

我正在为带有 package.json 的 Nodejs 项目的 docker 图像安装Sharp包以进行图像压缩。 当我创建容器时,我收到以下关于尖锐包装的错误:

/app/node_modules/sharp/lib/libvips.js:67 
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
 ^ Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.
at Object.hasVendoredLibvips (/app/node_modules/sharp/lib/libvips.js:67:13)
at Object.<anonymous> (/app/node_modules/sharp/lib/constructor.js:8:22)
at Module._compile (module.js:577:32) 
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32) 
at tryModuleLoad (module.js:453:12) 
at Function.Module._load (module.js:445:3) 
at Module.require (module.js:504:17) 
at require (internal/module.js:20:19) 
at Object.<anonymous> (/app/node_modules/sharp/lib/index.js:3:15)'.

我已删除整个 node_module 目录并在目录中重新运行npm install命令以重新安装所有包并重建 docker 映像,但我仍然收到错误消息。

任何有关如何解决此问题的建议表示赞赏。

我在使用 Docker 时遇到了同样的错误。 问题是我忘记包含一个.dockerignore文件,并且我的node_modules被复制到容器中。

尝试在项目的根目录(在 Dockerfile 旁边)创建一个.dockerignore文件,例如:

node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore

这是由于您在 Linux 平台上运行docker并且您的机器可能是 mac 或 windows 造成的。 大多数情况下,您可以使用相同的模块版本,但在使用诸如sharp之类的低级内核函数时则不行。

您需要在 Docker 和本地计算机上使用不同版本的Sharp

您可能已经在没有 docker 的情况下运行了您的项目,然后使用了 docker。

解决方案 1:您可以删除 package.lock + node_modules 文件夹,然后重新构建,现在只使用 docker。

解决方案 2:(不干净但可以提供帮助)从您的 package.json 中删除Sharp ,然后在您启动服务器时安装它。 例如通过更新你的 package.json:

包.json

{
  ...
  "scripts": {
    ...
    "start-docker": "yarn add sharp && nodemon index.js"
  },
  ...

您也可以在 Dockerfile 文件中执行此操作:

Dockerfile

FROM node:13
ADD package.json /package.json
RUN yarn install
RUN yarn add sharp
ENV NODE_PATH=/node_modules
ENV PATH=$PATH:/node_modules/.bin
WORKDIR /app
CMD ["yarn","start-docker"]

我遇到了多阶段 docker 文件的问题,其中两个图像基于不同的平台,我像这样解决了它:

FROM node:14 AS builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build

FROM node:14-alpine
WORKDIR /app
COPY --from=builder /app ./
RUN npm install sharp
CMD ["npm", "run", "start:prod"]

诀窍是在最终容器中安装 run npm install sharp - 在我的情况下,它是 Alpine linux,它与 node:14 的基本映像不同(显然它是不同的平台)。 Sharp 直接编译到特定平台,因此在一个容器中运行npm install并将那些已编译/预编译的文件复制到另一个容器无法正常工作。 我认为这仍然是更好的解决方案,然后回退到更大的节点:14 图像(仅运行容器)(在我的情况下为 1,4Gb -> 0.7Gb Alpine)。

请记住,您仍然应该拥有带有 node_modules 的 .dockeringore 文件并不能帮助您解决此问题。 它只是通过 CI 服务器或本地主机(使用不同的操作系统)上的缓存来加速进程构建。

干杯

圆形 CI 配置有同样的问题。 我正在安装 node_modules

docker: - image: cimg/node:16.14.0

并且正在运行我的构建工作

docker: - image: node:16-alpine

正因为如此,我有这样一个错误

/root/project/node_modules/favicons-webpack-plugin/src/index.js:562
    throw new Error(
          ^
Error: Could not find the npm peerDependency "favicons".
Please run:
npm i favicons
 - or -
yarn add favicons

Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linuxmusl-x64' platform.
    at loadFaviconsLibrary (/root/project/node_modules/favicons-webpack-plugin/src/index.js:562:11)
    at FaviconsWebpackPlugin.generateFaviconsWebapp (/root/project/node_modules/favicons-webpack-plugin/src/index.js:403:22)
    at FaviconsWebpackPlugin.generateFavicons (/root/project/node_modules/favicons-webpack-plugin/src/index.js:315:21)
    at /root/project/node_modules/favicons-webpack-plugin/src/index.js:117:18
    at /root/project/node_modules/favicons-webpack-plugin/src/cache.js:155:5
    at CacheFacade.providePromise (/root/project/node_modules/webpack/lib/CacheFacade.js:337:24)

Exited with code exit status 1
CircleCI received exit code 1

解决方案是在同一个 docker 镜像上运行所有这些作业

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM