Make ACE compatible with AWS Lambda by rewriting the JSON5 import statement

Open
#462 · Created  · Last updated

Description

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 and minipass-sized all require JSON5 as well. esbuild rewrites the JSON5 of ACE to JSON52 (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 with utils.loadJSON.

Changing the import statement from a require to an import 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!

0 attachments

0 comments

Loading commits...