Closed tusharr closed 2 weeks ago
Hello, thanks for sharing this. I had the same recently, and this is most likely a package versioning issue, that we should be able to fix. Until we do, the easiest way to overcome this issue is actually to build and deploy the solution from a linux-x64 platform, such an EC2 instance, or CloudShell.
The installation of platform-specific Sharp dependencies for Linux x64 architecture is handled in the prebuild script (as defined in package.json: https://github.com/aws-samples/image-optimization/blob/main/package.json#L8).
To ensure a smooth deployment to x64 Lambda functions, I need your confirmation on a couple of things:
npm run build
before executing cdk deploy
? This step is crucial to install the necessary dependencies./functions/image-processing/node_modules/@img
directory in your environment? Specifically, we're looking for the presence of @img/sharp-linux-x64
and @img/sharp-libvips-linux-x64
packages. These are essential for your Lambda function to work correctly on x64 architecture.Having these platform-specific dependencies in place will ensure successful deployment of your image optimization solution on x64 Lambda. If you could answer these questions, it would be very helpful in understanding the situation and determining if there's a potential bug!
You can manually install sharp and said dependencies too:
/functions/image-processing/node_modules
,/functions/image-processing/package.json
,/functions/image-processing/package-lock.json
,npm install -f --omit=optional --prefix functions/image-processing sharp@^0.33.3 @img/sharp-linux-x64 @img/sharp-libvips-linux-x64
I had the same issue as @tusharr and manually installing the sharp binaries like you mentioned have worked for me as a workaround.
https://github.com/aws-samples/image-optimization/issues/35#issuecomment-2026313394
I had the same issue and your answer helped me get the solution to work. Thank you!
Thank you @piotrekwitkowski after spending a whole day on trying to make this sample work you mentioning the exact packages needed really helped.
For future folks running into (pasting so that the error is searchable) "Something went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-linux-x64.node'\nRequire stack:\n- /var/task/node_modules/sharp/lib/sharp.js\n- /var/task/node_modules/sharp/lib/constructor.js\n- /var/task/node_modules/sharp/lib/index.js\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js\n\nPossible solutions:\n- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"\n- Install for the current runtime: \"npm install --platform=linux --arch=x64 sharp\"\n- Consult the installation documentation: https://sharp.pixelplumbing.com/install" "stack"
Just run build and then follow the steps mentioned by @piotrekwitkowski 's post. Alternate would be change the prebuild command to be the one thats mentioned above :)
@navamgupta thanks, glad it helped! Could you tell me what OS and CPU architecture you're running?
@piotrekwitkowski Sure, its an older macbook Big sur OS, intel core i7 x86-64 The problem was that the files generated with the command mentioned in the prebuild were darwin and not linux for reasons not yet clear to me, using the command your mentioned explicitly installed the right packages.
I am trying to run this example and running into issues.
Developer Environment - Mac M1 Deploying to AWS Lambda Node 20.x
When I try to fetch an optimized Image with a URL like
https:// YOURDISTRIBUTION.cloudfront.net/images/rio/1.jpeg?format=auto&width=300
, it returns an errorCloudwatch shows the following error:
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
After many attempts to fix this, I can't get the example to run. Any help is appreciated