Not Compiling node_modules in AWS SAM

I recently switched from Serverless Framework to AWS SAM and am having a deployment problem. It’s including the node_modules in the zip that it uploads to AWS Lambda, but it’s not actually compiling the ReScript code in the node_modules.

For example, using Jzon, in AWS Serverless, it’ll include node_modules in the zip file, and you’ll see Jzon.res and Jzon.js in the node_modules/rescript_jzon/src/ folder. Doing the same thing in AWS SAM, however, doesn’t seem to compile these .res files.

The .bs_config files between the 2 projects is the same. If I run the code locally, you can see the compiled code, but not in the build folder AWS SAM compiles to. I wonder if it’s skipping some kind of “build” step when running it’s own internal npm install and make a zip file? I’ll google that (since I know it has to do this same type of deal for Python, .NET, Go, etc). Any pointers, however, would help.

Update: It would appear AWS SAM wants you to include a makefile if you’re doing custom stuff, but I’m confused on how this works for TypeScript projects. I tried it, but it attempted to run rescript.exe on my Mac and failed… maybe I should stop until Monday.

I found a TypeScript example using esbuild. While esbuild is fast, AWS SAM invoking the Makefile is insanely slow. Even if I managed to get the Makefile to duplicate npm run build, it’s wayyy too slow; Serverless is instant.

Word of warning to those wishing to use ReScript for AWS Lambda, stick to Serverless framework instead of AWS SAM.