Make ACE compatible with AWS Lambda by rewriting the JSON5 import statement
Steffen Müller
Branch: addcraft-steffen/atlassian-connect-express:fix/aws-lambda
Branch: atlassian/atlassian-connect-express:master
Open
This pull request makes ACE compatible with AWS Lambda.
As is discussed in the dev community (here and here as well), ACE does not work when deployed inside an AWS Lambda function. I just spent half a day debugging the problem and found out the following:
The usual AWS Lambda build process flattens all imports and the lambda function itself into a single JS file. If the same library is imported from multiple dependencies,
esbuild
rewrites the dependency names, adding numbers to the imported symbols.For ACE, there is a collision for
JSON5
.@babel/core
,pvtsutils
andminipass-sized
all requireJSON5
as well.esbuild
rewrites theJSON5
of ACE toJSON52
(notice the “2”!), but somehow forgets to create the symbol with this name. This results in ACE crashing when it tries to parse the JSON config file withutils.loadJSON
.Changing the import statement from a
require
to animport
magically fixes the problem, the build works. This is the only line that has to be changed to enable ACE apps on lambda!I completely see that mixing the style of require/imports in the same file is an ugly solution. But it does the trick. We might not get the
esbuild
project to treat this bug, but we can make ACE compatible with one single, although ugly line.Please consider accepting the pull request to enable this use case and help the lonely souls in the dev community trying to find out what is going on. Thank you!