Issue building locally on Mac architecture for AWS Linux

I can run my lambda locally using serverless offline but if I build it locally with yarn build and then deploy using serverless deploy I encounter an error in my logs when requesting the endpoint. The error I see is:

“errorMessage”:“/var/task/node_modules/sqlite3/build/Release/node_sqlite3.node: invalid ELF header”

This I believe is due to running build on the Mac architecture and then deploying to the AWS Linux architecture, whereas the sqlite3 module needs to be installed on the AWS Linux architecture.

Is there a way to run the yarn install and yarn build on the AWS Linux architecture before deploying?