Closed Maoragai12 closed 1 year ago
Hi @Maoragai12, thanks for raising an issue.
After looking up for a bit, unfortunately, it seems like a limitation of ESBuild [1], and Shopify-api-node
was not designed to use with a bundler like ESBuild [2].
[1] - https://esbuild.github.io/api/#non-analyzable-imports [2] - https://github.com/MONEI/Shopify-api-node/issues/506
[1] suggested a workaround though:
The way to work around this issue is to mark the package containing this problematic code as external so that it's not included in the bundle. You will then need to ensure that a copy of the external package is available to your bundled code at run-time.
Hi @Maoragai12, thanks for raising an issue.
After looking up for a bit, unfortunately, it seems like a limitation of ESBuild [1], and
Shopify-api-node
was not designed to use with a bundler like ESBuild [2].[1] - https://esbuild.github.io/api/#non-analyzable-imports
[2] - https://github.com/MONEI/Shopify-api-node/issues/506
[1] suggested a workaround though:
The way to work around this issue is to mark the package containing this problematic code as external so that it's not included in the bundle. You will then need to ensure that a copy of the external package is available to your bundled code at run-time.
Hi, thanks for the explanation!
Regarding the suggestion - how can I include the package at runtime? There is any reference you can share please?
Hey @Maoragai12, apologies for the late response. One way of including a dependency after marking it as external from esbuild is to then create a Lambda Layer Version resource in your CFN stack that contains your dependency.
I will close this for now since this doesn't seem to be an AWS SAM CLI issue, but feel free to open a new issue if anything else comes up!
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
@Maoragai12 late to the party, but I have actually raised a PR to shopify-api-node
to address this issue
Description:
I'm using one of the resources and the methods of the Shopify SDK. When I build the Lambda I get no errors and everything is ok. After I deploy the Lambda and trigger it, I get the following error:
After some digging in the code, I understand that one of the methods in the
index
file of the SDK use dynamic require, and that's what calls the./order
file.The build configuration in the
template.yaml
:When I use makefile of my own with
webpack
instead ofesbuild
, everything works as expected.There is any problem with dynamic require in
esbuild
?Steps to reproduce:
Expected result:
The Lambda should be triggered with no errors.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 1.65.0