I have some issues deploying a serverless function. First, I use two big packages like google document-ai and aws-rekognition. When I try to deploy using these two, it fails since the .zip becomes too big. If I exclude the node_modules from the deployment, when I test the function it says it does not work. Now, I moved my two packages to use REST API calls, but I still have ‘sharp’ library for image processing, and unfortunately I cannot deploy the node_modules for it, since it’s not compatible from my OSX to Linux. So my question is, do DO functions do npm install, or I always have to sumit the node_modules folder?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey!
You don’t need to upload your node_modules
folder manually when deploying to DigitalOcean Functions. As long as you include a valid package.json
, DigitalOcean will run npm install --production
during deployment for you.
If you’re using native modules like sharp
, I think that it’s best to deploy with the --remote-build
flag:
doctl serverless deploy . --remote-build
This ensures the Functions service performs a remote build, which usually avoids compatibility issues that can come up when developing on macOS:
https://docs.digitalocean.com/products/functions/reference/build-process/#local-and-remote-builds
That said, sharp
and other native modules can still be tricky depending on how they’re bundled. If you continue hitting issues, I’d recommend reaching out to the DigitalOcean support team to dig deeper:
Hope this helps! Let us know how it goes!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.