digitalmaas / serverless-plugin-browserifier

Reduce the size and speed up your Node.js based lambda's using browserify.
Other
27 stars 4 forks source link

Issue with Sharp Library #57

Open vivrkerror404 opened 1 month ago

vivrkerror404 commented 1 month ago

Hi,

I am facing an issue with this module when I tried to minify the sharp - npm bundle in node.js & deployed it on serverless then I got the below error:

But without serverless-plugin-browserifier it is working fine on serverless

INIT_START Runtime Version: nodejs:18.v31 Runtime Version ARN: arn:aws:lambda:ap-south-1::runtime:8ece8834b939ff191c80d2c2482efff16a57464e3894a1ef66c15edae5018028 2024-08-11 17:21:42.378 ERROR Uncaught Exception {"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 179../libvips (/var/task/index.js:39563:9)"," at o (/var/task/index.js:1:631)"," at /var/task/index.js:1:682"," at 171../is (/var/task/index.js:34857:1)"," at o (/var/task/index.js:1:631)"," at /var/task/index.js:1:682"," at 172../channel (/var/task/index.js:35305:15)"," at o (/var/task/index.js:1:631)"," at /var/task/index.js:1:682"," at 1.express (/var/task/index.js:5:15)"]} INIT_REPORT Init Duration: 221.84 ms Phase: init Status: error Error Type: Runtime.Unknown

here is the browserifier configuration in serverless.yml file

` plugins:

custom: browserifier: external:

package: excludeDevDependencies: true individually: true include:

nolde commented 1 month ago

Hello!

Sharp seems to use native libs to work. Browserify can only bundle js files, and will not bundle the required native libraries.

Exclude sharp from the bundling, and add it as an inclusion in the package. Downside is that you need to make sure every dependency of sharp goes along with it.

You will have the same problem with any bundler you use, so this is not really a problem caused by serverless-plugin-browserifier.