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

标签 node.js linux docker npm platform

我正在使用 package.json 在 Nodejs 项目的 Docker 镜像上安装用于图像压缩的 Sharp 包。 当我创建容器时,我收到有关 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

关于node.js - linux-x64 二进制文件无法在 linuxmusl-x64 平台上使用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57932529/

相关文章:

java - 使用 docker 和 logback 记录到文件

networking - 不同VM的Docker主机之间的容器网络

docker - 使用 docker-py 获取正在运行的 docker 容器列表

sql-server - 无法使用 npm mssql 和 Node.js 将浮点值存储到 sql server

node.js - Gun.js 为什么会出现错误 "You have no persistence layer to save to error"

Linux命令需要翻译

php - 我可以用 PHP 运行 export DISPLAY 吗?

node.js - Monkey Patch 在发送响应之前重新调整响应

php - 如何像在 php 中一样将 URL 变量传递给 express.js?

linux - 无法正确解析 shell 中的多个选项