NodeJS build step exits early causing workflow to fail

I have a workflow which fails frequently due to the build step exiting before the build process is actually completed.

The failing step is a simple webpack build of a typescript react project. Half way through the build process, the step exits with code 0 and circle ci tries to proceed with the deployment step.

After re-running the job multiple times, the build step will eventually succeed, but there is no clue as to why it fails in the first place.

My first thought was a problem in our build script, but the fact that the succeeds eventually with the exact same source code makes me think there is a problem on the Circle CI side.

I have tried debugging the build step both locally in a circle ci node docker container, and by ssh’ing into the workflow container. I cannot reproduce the issue using either method, the build completes as expected 100% of the time.

Has anyone else experienced something similar? Any ideas on how to debug such a problem?