Could not load the "sharp" module using the win32-x64 runtime (Strapi)

4.9k views Asked by At

I used to use a Node.js v16.x installed locally to run Strapi which worked well.

But recently I had to update it to Node.js v18.x due to another project, so I installed NVM to manage multiple Node.js versions on my PC - and now I want to use Strapi with the new Node.js but I can't even start the develop mode anymore. There's a problem with the packge Sharp.

I'm not sure weather the issue with the package Sharp started because of the new Node version or NVM. As the Node installed (v18.17.0) is listed as compatible on Shap package npm page (here), I guess the problem is with NVM.

nvm list

  * 18.17.0 (Currently using 64-bit executable)
    16.14.2

My dependencies:

  "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"
  }

I've already tried to run the commands suggested on log (attached below) but nothing worked.

Does anyone know how to fix it?

enter image description here

5

There are 5 answers

1
Alexandre Paiva On

I was not able to fix it, not sure if it's something wrong with the sharp latest version 0.33.1 (that I had updated on my project).

I even tried to run the Strapi with Docker on a Linux image (node:18-alpine) but that issue still happen:

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)

The only solution was to downgrade to the previous version I was using (0.32.6), then it's working again.

0
Nico Serrano On

The following answer is related to the sharp error: Could not load the "sharp" module using the win32-x64 runtime and not specifically with Strapi.

It looks like sharp needs some builds to run in Windows and in /node_modules/sharp/lib/sharp.js (line 13) you can notice that they listed a couple of paths:

const paths = [
  `../src/build/Release/sharp-${runtimePlatform}.node`,
  '../src/build/Release/sharp-wasm32.node',
  `@img/sharp-${runtimePlatform}/sharp.node`,
  '@img/sharp-wasm32/sharp.node'
];
// as of February 17, 2024

To fix this error in Windows (using PowerShell terminal and not WSL) I installed @img/sharp-win32-x64 with npm i @img/sharp-win32-x64 --save-optional (notice the --save-optional flag) so when I run the same project in a Linux environment, npm will ignore @img/sharp-win32-x64 and safely continue.

This way in my particular case I am able to run my NodeJS project + sharp in Windows and Linux.

1
Kazi Mahbubur Rahman On
  1. Update your package manager

npm install -g npm@latest

  1. Clear the cache

npm cache clean -f

  1. Then Terminate batch job and run again

npm run dev

or

npm run start

0
M. Nicol On

Make sure optional dependencies are installed:

npm install --include=optional sharp
0
Ashraful Sm On

The problem is your npm package is not updated. When your package isn't matching with the sharp package. Easily Solving way is update your npm.

npm install -g npm@latest

if not working Clear the cache

npm cache clean -f

Then install the dependencies

npm i sharp

Hope working.