-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
serverless + esbuild + npm not including required platform dependencies #4213
Comments
Did you see https://sharp.pixelplumbing.com/install#esbuild and the serverless esbuild example? Watch out for the npm lockfile bug npm/cli#4828 too. |
The serverless esbuild example is meant for v3. v4 uses esbuild config file instead of a plugin, so it confuses me. |
https://sharp.pixelplumbing.com/install#esbuild
https://www.serverless.com/framework/docs/providers/aws/guide/building#configuration
Putting these two together would suggest something like the following is required: build:
esbuild:
external:
- sharp |
I already did that and didn't make a difference. The only thing that worked is using the patterns config in serverless.yml. |
esbuild doesn't support bundling native modules. My understanding is that this is intentional, which makes sense as it's relatively easy to mark packages as
This sounds like a limitation of the
Native modules should be packaged but not bundled, and your deployment zip file should contain a
My best guess would be because the https://www.serverless.com/framework/docs/providers/aws/guide/packaging#individual-function-packages suggests the following might be more appropriate: package:
individually: true
functions:
my-function-that-uses-sharp:
package:
patterns:
- 'node_modules/sharp'
- 'node_modules/@img' |
That makes sense now. Didn't know I could configure patterns per function.
Thanks!
…On Fri, Sep 6, 2024, 16:11 Lovell Fuller ***@***.***> wrote:
Why isn't esbuild including the required platform specific dependencies
itself?
Why do I need to exclude sharp from bundling?
esbuild doesn't support bundling native modules. My understanding is that
this is intentional, which makes sense as it's relatively easy to mark
packages as external to *bundling*.
Why do I need to hard-code the inclusion of this platform-specific module
in all the functions I deploy?
This sounds like a limitation of the serverless tooling. If you mark
packages as external at *bundle time* then it would make sense for these
to be automagically included at *package time*, but that doesn't (yet)
appear to be a feature.
How does the lambda function find sharp if it is not in the bundle?
Native modules should be *packaged* but not *bundled*, and your
deployment zip file should contain a node_modules directory with native
modules.
I can see in the deployment package that sharp is in the node_modules of
every other lambda function that does not even use sharp at all. How's that?
My best guess would be because the serverless configuration you've
provided suggests you're telling it to always include it via
package.patterns for all functions.
https://www.serverless.com/framework/docs/providers/aws/guide/packaging#individual-function-packages
suggests the following might be more appropriate:
package:
individually: truefunctions:
my-function-that-uses-sharp:
package:
patterns:
- 'node_modules/sharp'
- ***@***.***'
—
Reply to this email directly, view it on GitHub
<#4213 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADS4ZWKIDIAF7SKTLJDTTTZVH46HAVCNFSM6AAAAABNYOSMQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZUGY3DINJRGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I hope this information helped. Please feel free to re-open with more details if further assistance is required. |
Question about an existing feature
What are you trying to achieve?
Trying to deploy a Lambda function using Serverless v4 + esbuild + npm v10
When you searched for similar issues, what did you find that might be related?
I'm having issues including the optional/required binary platform-dependent dependencies to make the lib work. None of the documented instructions on the cross-platform section helped overcome this issue.
The error I get while executing the lambda is
Could not load the "sharp" module using the linux-x64 runtime
.After following all the instructions in the docs, the only thing that worked for me is adding the following lines in the serverless.yml file, but I can't make sense of it.
@img/sharp-libvips-linux-x64
as a dependency?Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
Just try to resize an image using sharp. Runtime error is thrown:
Please provide sample image(s) that help explain this question
?
Thanks!
The text was updated successfully, but these errors were encountered: