Failed to build with worker

Since I added a worker to my application, every time that I try to build my app, e get the following return:

Error: Failed to build function “packages/functions/src/lambda.handler”
No loader is configured for “.node” files: node_modules/@swc/core/node_modules/@swc/core-darwin-arm64/swc.darwin-arm64.node
node_modules/@swc/core/binding.js
170 │ return require(‘@swc/core-darwin-arm64’);
Could not resolve “__temporal_custom_payload_converter”
node_modules/@temporalio/workflow/lib/worker-interface.js
91 │ const customPayloadConverter = require(‘__temporal_custom_payload_converter’).payloadConverter;
Could not resolve “__temporal_custom_failure_converter”
node_modules/@temporalio/workflow/lib/worker-interface.js
98 │ const customFailureConverter = require(‘__temporal_custom_failure_converter’).failureConverter;

Does anyone know how to fix it?

It looks like you are trying to bundle the @temporalio/worker and @temporalio/workflow packages. This is not supported.

If you really need to bundle your Temporal Worker’s code, you will need to configure your bundler to keep the following packages as external:

  • @temporalio/worker
  • @temporalio/workflow
  • @temporalio/core-bridge
  • @temporalio/common
  • @temporalio/worker
  • @temporalio/proto

You will also need to pre-bundle your workflow code, e.g. by using bundleWorkflowCode() from your building script. See this sample. The file containing your Workflow Bundle’s code will also need to be marked as external.