'ERROR with sharp dependency when deploying nodejs app to AWS elastic beanstalk

i am a beginner in AWS, and I encountered this problem very early on. I created an EB environment and a code-pipeline in AWS. So whenever I push something to the repository, the app gets deployed. So for now I just have a "Hello world" node.js app, but I want to install the sharp npm dependency for later on. When I put the dependency in the package.json file and push it to the repo, a get the following error: error on deployment. I have done a lot of googling, and I think it has something to do with setting permissions to install the sharp dependency. However, none of the solutions I found have worked so far. If anything is unclear, I apologize and let me know :).



Solution 1:[1]

Please reference my "workaround" solution provided in the following GitHub Issue (Fails to install on AWS ElasticBeanstalk with node16 #3221) for a full explanation.

Solution:

  1. Create the following Platform Hooks paths in the root directory of your application bundle.
  • .platform/hooks/prebuild
  • .platform/confighooks/prebuild
  1. Create the following bash script (00_npm_install.sh) with execute permissions (chmod +x).
#!/bin/bash
cd /var/app/staging
sudo -u webapp npm install sharp
  1. Validate the Application Bundle Structure.

Ex. Sample project structure:

~/my-app/
??? app.js
??? index.html
??? .npmrc_bkp
??? package.json
??? package-lock.json
??? .platform
?   ??? confighooks
?   ?   ??? prebuild
?   ?       ??? 00_npm_install.sh
?   ??? hooks
?       ??? prebuild
?           ??? 00_npm_install.sh
??? Procfile
  1. Deploy the Application!

Hope it helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jceduar