Unable to install external js dependency after version >= 1.94.0

Describe the problem/error/question

Before 1.93.0, in a docker compose deployment, we been using below Dockerfile to install sharp within the:

FROM docker.n8n.io/n8nio/n8n:1.94.0
USER root
RUN npm install -g sharp
USER node

It’s been working fine ever since. However, after we upgrade to version >= 1.94.0, I have the following error

In the beginning we suspect the “sharp“ module installed globally didn’t come with platform-specific dependencies, but when we look into /usr/local/lib/node_modules/sharp/node_modules/, it actually has sharp-libvips-linuxmusl-x64 and sharp-linux-musl-x64 installed

When we look into /usr/local/lib/node_modules/n8n/.pnpm/[email protected]/node_modules, we found another version of sharp, which comes without the platform-specific dependencies

Wonder what should be done to workaround this?

What is the error message (if any)?

Stack Trace attached

Error: Could not load the "sharp" module using the linuxmusl-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=linux --libc=musl --cpu=x64 sharp - Consult the installation documentation: See https://sharp.pixelplumbing.com/install at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/sharp/lib/sharp.js:113:9) at Module._compile (node:internal/modules/cjs/loader:1706:14) at Object..js (node:internal/modules/cjs/loader:1839:10) at Module.load (node:internal/modules/cjs/loader:1441:32) at Function._load (node:internal/modules/cjs/loader:1263:12) at TracingChannel.traceSync (node:diagnostics_channel:328:14) at wrapModuleLoad (node:internal/modules/cjs/loader:237:24) at Module.require (node:internal/modules/cjs/loader:1463:12) at require (node:internal/modules/helpers:147:16) at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected]/node_modules/sharp/lib/constructor.js:10:1)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.94.0 ~ 1.120.1
  • Database (default: SQLite): PG
  • n8n EXECUTIONS_PROCESS setting (default: own, main): N/A
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux