无法使用 win32-x64 运行时 (Strapi) 加载“sharp”模块

问题描述 投票:0回答:1

我曾经使用本地安装的 Node.js v16.x 来运行 Strapi,效果很好。

但最近由于另一个项目,我不得不将其更新到 Node.js v18.x,因此我安装了 NVM 来管理我的 PC 上的多个 Node.js 版本 - 现在我想将 Strapi 与新的 Node.js 一起使用,但我甚至无法再启动开发模式。 Sharp 的包装有问题。

我不确定 Sharp 包的问题是否是由于新的 Node 版本或 NVM 引起的。由于已安装的 Node(v18.17.0)在 Shap 包 npm 页面(here)上被列为兼容,我猜问题出在 NVM 上。

nvm list

  * 18.17.0 (Currently using 64-bit executable)
    16.14.2

我的依赖:

  "dependencies": {
    "@strapi/plugin-i18n": "4.16.2",
    "@strapi/plugin-users-permissions": "4.16.2",
    "@strapi/provider-email-amazon-ses": "4.16.2",
    "@strapi/provider-upload-aws-s3": "4.16.2",
    "@strapi/strapi": "4.16.2",
    "@strapi/utils": "4.16.2",
    "pg": "8.11.3",
    "reach": "1.0.1",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-router-dom": "5.2.0",
    "sharp": "^0.33.1",
    "slugify": "1.6.6",
    "strapi-plugin-config-sync": "1.2.3",
    "strapi-plugin-email-designer": "2.2.1",
    "strapi-plugin-entity-relationship-chart": "4.14.6",
    "strapi-plugin-import-export-entries": "1.23.1",
    "strapi-plugin-notes": "1.1.2",
    "strapi-plugin-placeholder": "4.4.0",
    "strapi-plugin-publisher": "1.5.6",
    "styled-components": "5.2.1"
  },
  "engines": {
    "node": ">=14.x.x <=18.x.x",
    "npm": ">=6.0.0"
  }

我已经尝试运行日志中建议的命令(附在下面),但没有任何效果。

有谁知道如何解决吗?

node.js strapi nvm sharp
1个回答
0
投票

我无法修复它,不确定 Sharp v0.33.x 是否有问题(我已在项目中更新)。

我什至尝试在 Linux 映像上使用 Docker 运行 Strapi (

node:18-alpine
),但问题仍然发生:

Error: Could not load js config file
/opt/node_modules/strapi-plugin-placeholder/strapi-server.js: Could not load the "sharp" module using the linuxmusl-x64 runtime.

Possible solutions:
- Ensure optional dependencies can be installed:
  npm install --include=optional sharp
  yarn add sharp --ignore-engines
- Ensure your package manager supports multi-platform installation:
  See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
  npm install --os=linuxmusl --cpu=x64 sharp
  npm install --force @img/sharp-linuxmusl-x64
- Consult the installation documentation:
  See https://sharp.pixelplumbing.com/install

at loadJsFile (/opt/node_modules/@strapi/strapi/dist/core/app-configuration/load-config-file.js:18:13)
at Module.loadFile (/opt/node_modules/@strapi/strapi/dist/core/app-configuration/load-config-file.js:37:14)
at Object.loadPlugins (/opt/node_modules/@strapi/strapi/dist/core/loaders/plugins/index.js:90:41)
at async Strapi.loadPlugins (/opt/node_modules/@strapi/strapi/dist/Strapi.js:310:5)
at async Promise.all (index 3)
at async Strapi.register (/opt/node_modules/@strapi/strapi/dist/Strapi.js:340:5)
at async Strapi.load (/opt/node_modules/@strapi/strapi/dist/Strapi.js:424:5)
at async Object.develop (/opt/node_modules/@strapi/admin/dist/_chunks/index-ffd2f664.js:1245:28)
at async develop (/opt/node_modules/@strapi/admin/dist/_chunks/develop-da585b1e.js:52:5)
at async Command.parseAsync (/opt/node_modules/commander/lib/command.js:923:5)
at async Module.runStrapiCommand (/opt/node_modules/@strapi/strapi/dist/commands/index.js:124:3)

唯一的解决方案是降级到我之前使用的版本(0.32.6),然后它又可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.