Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not load the "sharp" module using the linux-x64 runtime on AWS Lambda #4001

Closed
3 tasks done
tpamsler opened this issue Feb 20, 2024 · 10 comments
Closed
3 tasks done

Comments

@tpamsler
Copy link

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

Cannot run above command as it's executed on AWS Lambda nodejs20.x

What are the steps to reproduce?

Execute lambda on AWS Lambfda

What is the expected behaviour?

Lambda function should load "sharp" image library without arrores

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

const sharp = require('sharp');

Please provide sample image(s) that help explain this problem

{
"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",
"trace": [
"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 Object. (/var/task/node_modules/sharp/lib/sharp.js:114:9)",
" at Module._compile (node:internal/modules/cjs/loader:1376:14)",
" at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)",
" at Module.load (node:internal/modules/cjs/loader:1207:32)",
" at Module._load (node:internal/modules/cjs/loader:1023:12)",
" at Module.require (node:internal/modules/cjs/loader:1235:19)",
" at require (node:internal/modules/helpers:176:18)",
" at Object. (/var/task/node_modules/sharp/lib/constructor.js:10:1)",
" at Module._compile (node:internal/modules/cjs/loader:1376:14)",
" at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)"
]
}

@tpamsler
Copy link
Author

Update: Following the execution of npm install --cpu=x64 --os=linux sharp on my development system prior to deploying the code to AWS Lambda using Serverless Framework, everything is now functioning correctly.

@lovell lovell removed the triage label Feb 21, 2024
@lovell
Copy link
Owner

lovell commented Feb 21, 2024

https://sharp.pixelplumbing.com/install#aws-lambda
https://sharp.pixelplumbing.com/install#cross-platform

If you still require help, please open a new installation issue and answer all of the questions.

@lovell lovell closed this as completed Feb 21, 2024
@eudoroolivares2016
Copy link

eudoroolivares2016 commented Feb 22, 2024

I am seeing the same issue @tpamsler you mentioned that as the solution but, for me running the npm install --cpu=x64 --os=linux sharp does not result in any changes to my package-lock file but, my development machine is macOs and I am using "sharp": "^0.33.2" as well.

@eudoroolivares2016
Copy link

My result from npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp is
System: OS: macOS 13.6.4 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 142.20 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm npmPackages: sharp: ^0.33.2 => 0.33.2
So I believe that something is blocking the install from occurring as expected

@tpamsler
Copy link
Author

I just ran npm install --cpu=x64 --os=linux sharp before deploying the lambda to AWS via serverless deploy ... and it had the correct binary in node_mudules during the deploy.

@eudoroolivares2016
Copy link

eudoroolivares2016 commented Feb 23, 2024

@tpamsler if you run that on your local machine or otherwise if you can see what went into the lambda, do you see what hte binaries are in the node_modules. Going into the node_modules/@img I see sharp-darwin-x64 sharp-libvips-darwin-x64 but, I actually do not see the linux values: node_modules/@img/sharp-libvips-linux-arm and others in my package-lock file as I have run that same npm install targeted for linux

@tpamsler
Copy link
Author

tpamsler commented Feb 23, 2024 via email

@eudoroolivares2016
Copy link

eudoroolivares2016 commented Feb 23, 2024

@tpamsler Would you mind posting your package.json and/or package-lock.json file. I'm interested if there are any diffs between. I can get these linux binaries by doing a npm install --force @img/sharp-linux-x64 etc. But, that is not good practice. It also leads to issues because then it'll try to install those on the dev machine and fail.

@tpamsler
Copy link
Author

package-lock.json
package.json

@trippingcats
Copy link

I hope this helps somebody: For me installing the packages manually was the only way to make it work on AWS, I am using Sharp v0.33.4, this it is probably not a good practice (as mentioned) but at least it works.

npm install @img/sharp-darwin-arm64 @img/sharp-libvips-darwin-arm64 @img/sharp-libvips-linux-x64 @img/sharp-libvips-linuxmusl-x64 @img/sharp-linux-x64 @img/sharp-linuxmusl-x64 --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants