When using sharp with a bundler, it is recommended to externalize the sharp dependency to mitigate the issue described here where the bundle is created with the macos-specific addon instead of the linux-specific addon. https://sharp.pixelplumbing.com/install#esbuild
If we simply install the sharp dependency and import it to our function, we will encounter the following error at runtime:
{
"errorType": "Error",
"errorMessage": "Could not load the \"sharp\" module using the linux-x64 runtime\nPossible solutions:\n- Ensure optional dependencies can be installed:\n npm install --include=optional sharp\n yarn add sharp --ignore-engines\n- Ensure your package manager supports multi-platform installation:\n See https://sharp.pixelplumbing.com/install#cross-platform\n- Add platform-specific dependencies:\n npm install --os=linux --cpu=x64 sharp\n- Consult the installation documentation:\n See https://sharp.pixelplumbing.com/install",
"stack": [
"Error: Could not load the \"sharp\" module using the linux-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=linux --cpu=x64 sharp",
"- Consult the installation documentation:",
" See https://sharp.pixelplumbing.com/install",
" at node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/sharp.js (file:///var/task/index.mjs:2642:13)",
" at __require2 (file:///var/task/index.mjs:19:50)",
" at node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/constructor.js (file:///var/task/index.mjs:2655:5)",
" at __require2 (file:///var/task/index.mjs:19:50)",
" at node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/index.js (file:///var/task/index.mjs:6821:17)",
" at __require2 (file:///var/task/index.mjs:19:50)",
" at file:///var/task/index.mjs:6836:28",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
]
}
This will impact any non-AL2023 deployments (i.e. sandbox deployments from macos, windows, and custom deployments from non-linux runners). From some other issues, this seems to be where it is recommended to force a build with docker instead of esbuild from the project.
Environment information
Description
When using sharp with a bundler, it is recommended to externalize the
sharp
dependency to mitigate the issue described here where the bundle is created with the macos-specific addon instead of the linux-specific addon. https://sharp.pixelplumbing.com/install#esbuildIf we simply install the
sharp
dependency and import it to our function, we will encounter the following error at runtime:This will impact any non-AL2023 deployments (i.e. sandbox deployments from macos, windows, and custom deployments from non-linux runners). From some other issues, this seems to be where it is recommended to force a build with docker instead of esbuild from the project.