I’m working with a TypeScript monorepo. When running the Temporal worker locally, everything works as expected — the worker starts up correctly and is able to process workflows without any issues.
However, when running the worker from the build (production) environment, the worker starts fine, but as soon as a workflow is triggered, I encounter the following error:
[ERROR] Failed to process Workflow Activation {
sdkComponent: ‘worker’,
taskQueue: ‘appointment-confirmation-task-queue’,
runId: ‘0198170c-c5ae-7e09-865e-6876655fc581’,
error: /Users/sandeep-ah/Desktop/projects1/asha/api/build/workflow-bundle-b304755c459f4d72a5dc.js:8957
throw e;
^
Error: Cannot find module ‘@temporalio/workflow’
at webpackEmptyContext (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows|sync:2:0)
at /Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:22:0
at /Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:12:0
at ./temporalWorkerWorkflows/index.js (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:18:1)
at webpack_require (webpack/bootstrap:19:0)
at importWorkflows (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index-autogenerated-entrypoint.cjs:9:9)
at Object.initRuntime (/Users/sandeep-ah/Desktop/projects1/asha/node_modules/@temporalio/workflow/src/worker-interface.ts:78:16)
at __TEMPORAL_CALL_INTO_SCOPE (evalmachine.:30:40)
at evalmachine.:1:1
at Script.runInContext (node:vm:149:12),
workflowExists: false
}
2025-07-17T06:22:49.948496Z WARN temporal_sdk_core::worker::workflow: Failing workflow task run_id=0198170c-c5ae-7e09-865e-6876655fc581 failure=Failure { failure: Some(Failure { message: “Cannot find module ‘@temporalio/workflow’”, source: “TypeScriptSDK”, stack_trace: “/Users/sandeep-ah/Desktop/projects1/asha/api/build/workflow-bundle-b304755c459f4d72a5dc.js:8957\n\tthrow e;\n\t^\n\nError: Cannot find module ‘@temporalio/workflow’\n at webpackEmptyContext (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows|sync:2:0)\n at /Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:22:0\n at /Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:12:0\n at ./temporalWorkerWorkflows/index.js (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index.js:18:1)\n at webpack_require (webpack/bootstrap:19:0)\n at importWorkflows (/Users/sandeep-ah/Desktop/projects1/asha/api/build/temporalWorkerWorkflows/index-autogenerated-entrypoint.cjs:9:9)\n at Object.initRuntime (/Users/sandeep-ah/Desktop/projects1/asha/node_modules/@temporalio/workflow/src/worker-interface.ts:78:16)\n at __TEMPORAL_CALL_INTO_SCOPE (evalmachine.:30:40)\n at evalmachine.:1:1”, encoded_attributes: None, cause: None, failure_info: None }), force_cause: Unspecified }
worker initialization code:
import { NativeConnection, Worker } from ‘@temporalio/worker’;
import * as activities from ‘./temporal/activities’;
import { config, constants } from ‘./temporal/config’;
async function run() {
try {
const connection = await NativeConnection.connect({
address: config.address,
apiKey: config.apiKey,
tls: {},
});
const worker = await Worker.create({
connection,
namespace: config.namespace,
workflowsPath: require.resolve('./temporalWorkerWorkflows'),
activities,
taskQueue: constants.APPOINTMENT_CONFIRMATION_TASK_QUEUE,
});
await worker.run();
} catch (error) {
console.error(‘[TEMPORAL_WORKER] Error:’, error);
process.exit(1);
}
}
run().catch((err) => {
console.error(‘[TEMPORAL_WORKER] Unhandled error:’, err);
process.exit(1);
});