sharp icon indicating copy to clipboard operation
sharp copied to clipboard

MacOS to Windows server deployment issue

Open Fizz-pop-bang opened this issue 9 months ago • 3 comments

Hopefully you'll understand...

I've developed a project using Angular 19, SSR and quite a few API endpoints are using NodeJs. I guess I should state my dev machine is a Macbook.

Angular CLI: 19.2.13 Node: 22.11.0 Package Manager: npm 10.9.0 OS: darwin arm64

All of this is built and deployed on a Windows server (shared hosting) and the project works as intended.

When I hook up the files that use the Sharp plugin, everything still works on the Macbook, but when deployed to the Windows server I get the error below:

Failed to import app: Error: Could not load the "sharp" module using the win32-x64 runtime Possible solutions:

  • Ensure optional dependencies can be installed: npm install --include=optional sharp
  • Ensure your package manager supports multi-platform installation: See https://sharp.pixelplumbing.com/install#cross-platform
  • Add platform-specific dependencies: npm install --os=win32 --cpu=x64 sharp
  • Consult the installation documentation: See https://sharp.pixelplumbing.com/install at file:///C:/Inetpub/vhosts/www/server/server.mjs:127:38442 at file:///C:/Inetpub/vhosts/www/server/chunk-S6KH3LOX.mjs:2:1047 at file:///C:/Inetpub/vhosts/www/server/server.mjs:128:80 at file:///C:/Inetpub/vhosts/www/server/chunk-S6KH3LOX.mjs:2:1047 at file:///C:/Inetpub/vhosts/www/server/server.mjs:128:80144 at file:///C:/Inetpub/vhosts/www/server/chunk-S6KH3LOX.mjs:2:1047 at file:///C:/Inetpub/vhosts/www/server/server.mjs:131:1204 at ModuleJob.run (node:internal/modules/esm/module_job:195:25) at async ModuleLoader.import (node:internal/modules/esm/loader:337:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:432:15) (node:217584) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use node --trace-deprecation ... to show where the warning was created)

I've tried

npm install --include=optional sharp npm install --os=win32 --cpu=x64 sharp

...but to no avail.

Fizz-pop-bang avatar May 25 '25 15:05 Fizz-pop-bang

Windows server is shared hosting, with iisnode.

Fizz-pop-bang avatar May 25 '25 15:05 Fizz-pop-bang

Ensure your package manager supports multi-platform installation: See https://sharp.pixelplumbing.com/install#cross-platform

Did you see this section of the docs linked to in the error message?

It also looks like you're using a code bundler, please see https://sharp.pixelplumbing.com/install/#bundlers

lovell avatar May 25 '25 16:05 lovell

@Fizz-pop-bang Were you able to make any progress with this?

lovell avatar Jun 12 '25 22:06 lovell

I'm having similar issues, upgrading from 0.34.1 to 0.34.2 everything breaks. However, I'm on the macOS, and I'm deploying to Linux. I'm using sharp in Next JS. This is the error I'm seeing in the CI:

#17 19.27 Error: Could not load the "sharp" module using the linuxmusl-x64 runtime
#17 19.27 ERR_DLOPEN_FAILED: Error loading shared library libvips-cpp.so.8.16.1: No such file or directory (needed by /app/node_modules/next/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-x64.node)
#17 19.27 Possible solutions:
#17 19.27 - Ensure optional dependencies can be installed:
#17 19.27     npm install --include=optional sharp
#17 19.27 - Ensure your package manager supports multi-platform installation:
#17 19.27     See https://sharp.pixelplumbing.com/install#cross-platform
#17 19.27 - Add platform-specific dependencies:
#17 19.27     npm install --os=linux --libc=musl --cpu=x64 sharp
#17 19.27 - Consult the installation documentation:
#17 19.27     See https://sharp.pixelplumbing.com/install
#17 19.27     at Object.<anonymous> (/app/node_modules/next/node_modules/sharp/lib/sharp.js:121:9)
#17 19.27     at Module._compile (node:internal/modules/cjs/loader:1529:14)
#17 19.27     at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
#17 19.27     at Module.load (node:internal/modules/cjs/loader:1275:32)
#17 19.27     at Module._load (node:internal/modules/cjs/loader:1096:12)
#17 19.27     at Module.require (node:internal/modules/cjs/loader:1298:19)
#17 19.27     at mod.require (/app/node_modules/next/dist/server/require-hook.js:65:28)
#17 19.27     at require (node:internal/modules/helpers:182:18)
#17 19.27     at Object.<anonymous> (/app/node_modules/next/node_modules/sharp/lib/constructor.js:10:1)
#17 19.27     at Module._compile (node:internal/modules/cjs/loader:1529:14)

Pinning sharp in package.json to 0.34.1 solves the issue.

majksner avatar Jun 26 '25 06:06 majksner

@majksner You mention upgrading/pinning sharp, but you probably don't need to do any of this as Next.js already includes sharp as one of its dependencies and performs its own bundling in standalone mode. If you're still having problems, please open a new installation issue and answer all of the questions.

lovell avatar Jun 26 '25 07:06 lovell

I’ve solved it by migrating to pnpm. Thanks anyway.

majksner avatar Jun 26 '25 17:06 majksner

@Fizz-pop-bang Closing due to inactivity but please feel free to reopen with more details if further help is required.

lovell avatar Jun 26 '25 18:06 lovell