How to Exclude Binary Dependencies from Workflow Bundle?

How can i exclude binary dependencies from the workflow bundle?

Using the recommend webpack method of externals is causing my workflows not to be found at run-time, and the bundle won’t build at all with the dependency included.

The worker and the workflow worked fine prior to adding this necessary dependency.

Worker:

  const worker = await Worker.create({
    connection,
    namespace: process.env['TEMPORAL_NAMESPACE'],
    taskQueue: process.env['TEMPORAL_TASK_QUEUE'] ?? 'default',
    activities,
    ...workflows,
    bundlerOptions: {
      webpackConfigHook: (config) => {
        // Don't build Sharp bc it has binary dependencies
        config.externals = {
          sharp: 'commonjs sharp',
        };
...

Error:

2024-04-24T13:15:44.914Z [ERROR] Failed to activate workflow {
  runId: 'c58ce0e8-46f9-4088-ad51-b027a84060de',
  error:** /Users/jelling/dev/rbt/rbt-nx/app/worker/dist/worker/workflow.bundle.js:144039**
  class ExponentialBackoffPoller extends events_1.EventEmitter {
                                                  ^
  
  TypeError: Class extends value undefined is not a constructor or null
      at ../../node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/utils/api-request.js (/Users/jelling/dev/rbt/rbt-nx/node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/utils/api-request.js:690:0)
      at __webpack_require__ (webpack/bootstrap:19:0)
      at ../../node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/app/credential-internal.js (/Users/jelling/dev/rbt/rbt-nx/node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/app/credential-internal.js:25:22)
      at __webpack_require__ (webpack/bootstrap:19:0)
      at ../../node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/utils/index.js (/Users/jelling/dev/rbt/rbt-nx/node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/utils/index.js:21:30)
      at __webpack_require__ (webpack/bootstrap:19:0)
      at ../../node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/app/index.js (/Users/jelling/dev/rbt/rbt-nx/node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/app/index.js:21:16)
      at __webpack_require__ (webpack/bootstrap:19:0)
      at ../../node_modules/.pnpm/firebase-admin@11.11.1/node_modules/firebase-admin/lib/esm/app/index.js (null:null:null)
      at __webpack_require__ (webpack/bootstrap:19:0),
  workflowExists: false

I replied in a DM in slack but posting here for posterity:

Seems like your code is using EventEmitter which isn’t supported in the workflow sandbox.

Don’t import events or any other Node dependencies.

This is likely a sign that you’re importing something shared between workflows and activities.
The recommended approach to solve this is to create a shared or common package that will work in both the Node.js environment and the deterministic JS sandbox that workflows run in.

We document this here: Foundations - TypeScript SDK feature guide | Temporal Documentation

You were right, it was an import that wasn’t wrapped in a proxy, not anything related to the webpack exclusion.

Is there anyway to programmatically detect these issues, meaning specifying which workflow and line it’s happening at? Our project is an NX mono repo so even though we know to separate packages, it’s easy for VSCode to auto-import the wrong dependency.