Error when starting worker

Hello

I am running a very simple temporal worker:

import { Worker } from '@temporalio/worker';
import { testTaskPipelineServiceActivites } from "./temporal-test/temporal-pipeline-service-activities"

async function run() {
  // Step 1: Register Workflows and Activities with the Worker and connect to
  // the Temporal server.
  const taskPipelineServiceWorker = await Worker.create({
    //activities: testTaskPipelineServiceActivites,
    taskQueue: 'task-pipeline-service',
    namespace: 'test',
  });
  // Worker connects to localhost by default and uses console.error for logging.
  // Customize the Worker by passing more options to create():
  // https://typescript.temporal.io/api/classes/worker.Worker

  // If you need to configure server connection parameters, see the mTLS example:
  // https://github.com/temporalio/samples-typescript/tree/main/hello-world-mtls

  // Step 2: Start accepting tasks on the `tutorial` queue
  await taskPipelineServiceWorker.run();

  // You may create multiple Workers in a single process in order to poll on multiple task queues.
}

if (require.main === module) {
  run().catch(err => {
    // eslint-disable-next-line no-console
    console.error('Error running Temporal worker', err);
    process.exit(1);
  });
}

and when i try to start the worker it first starts fine, but in a few seconds i get:

âžś  task-pipeline git:(test_taskpipelinev3_orchestration) âś— yarn temporal-worker
2022-06-14T20:29:39.641Z [INFO] Worker state changed { state: 'RUNNING' }
2022-06-14T20:30:36.718Z [ERROR] Worker failed {
  error: TypeError: (seconds || long_1.default.UZERO).mul is not a function
      at tsToMs (/Users/jackwang/scaleapi/.yarn/cache/@temporalio-internal-workflow-common-npm-0.23.0-6ffdfa1d79-6bc4b7524b.zip/node_modules/@temporalio/internal-workflow-common/lib/time.js:30:10)
      at extractActivityInfo (/Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:1039:69)
      at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:360:42
      at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/tracing.js:65:20
      at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:349:24
}
2022-06-14T20:30:36.720Z [INFO] Worker state changed { state: 'FAILED' }
Error running Temporal worker TypeError: (seconds || long_1.default.UZERO).mul is not a function
    at tsToMs (/Users/jackwang/scaleapi/.yarn/cache/@temporalio-internal-workflow-common-npm-0.23.0-6ffdfa1d79-6bc4b7524b.zip/node_modules/@temporalio/internal-workflow-common/lib/time.js:30:10)
    at extractActivityInfo (/Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:1039:69)
    at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:360:42
    at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/tracing.js:65:20
    at async /Users/jackwang/scaleapi/.yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip/node_modules/@temporalio/worker/lib/worker.js:349:24

i think this is a dependency issue somewhere. I added:

    "long": "5.2.0",

to my dependencies to no effect.

Hey jwang, welcome! If you’re using yarn3 and have temporalio in your package.json, could you try replacing it with the direct deps instead? Like @temporalio/worker etc.

i’ve tried having:

    "@temporalio/common": "0.23.x",
    "@temporalio/worker": "0.23.x",
    "@temporalio/workflow": "0.23.x",

and

    "@temporalio/common": "0.23.x",
    "@temporalio/worker": "0.23.x",
    "@temporalio/workflow": "0.23.x",
    "temporalio": "0.23.x",

and both give me that error

i am using yarn 3.2.0

I failed to reproduce—I’m guessing there must be something different about how I’m using yarn. Can you tell what the difference is?

I made these changes:

and then did:

git clone https://github.com/temporalio/samples-typescript.git
cd samples-typescript/hello-world
git checkout yarn
yarn install
yarn start

yarn workflow

I think the biggest difference here might be the fact that the repo where the worker breaks depends on both temporal packages and another repo that depends on the same temporal packages:
this is the repo where i see the error:

    "@scale/temporal-workflows": "portal:../temporal-workflows",
    "@temporalio/common": "0.23.x",
    "@temporalio/worker": "0.23.x",
    "@temporalio/workflow": "0.23.x",
    "temporalio": "0.23.x",

it depends on temporal-workflows which further has these dependencies:

    "@temporalio/common": "0.23.x",
    "@temporalio/worker": "0.23.x",
    "@temporalio/workflow": "0.23.x",
    "lodash": "^4.17.21",
    "modern-async": "^1.1.2",
    "serialize-error": "^8",
    "temporalio": "0.23.x"

Can you tell what the difference is?

@loren He is using the PNP linker instead of node-modules. This is visible from the fact that paths in the stack trace includes a “.zip” file (ie. .yarn/cache/@temporalio-worker-npm-0.23.2-c07b874de2-c8f05a7948.zip). That could possibly be part of the explanation, though I doubt that’s the only issue here.

@jwang97 I know this might not be ideal, but just to help get a better understanding of this issue, would it be possible for you to try configuring yarn in a more “classic NPM” style… For example, you may try adding the following lines in your .yarnrc file:

nodeLinker: node-modules
nmHoistingLimits: none

or

nodeLinker: pnp
nmHoistingLimits: none
pnpMode: loose

I know that Temporal packages are currently missing a few dependencies (mostly peerDependencies to other Temporal packages, but there’s some more). These missing dependencies would not pose issue in environments where the package manager does dependency hoisting, since they are dependencies of sibling packages. But you are likely to get issues with stricter package managers.

In my PNPM projects, I add the following dependency overrides in the root pacakge.json file:

    "pnpm": {
        "packageExtensions": {
            "@temporalio/activity": {
                "peerDependencies": {
                    "@temporalio/common": "*",
                    "@temporalio/internal-workflow-common": "*",
                    "abort-controller": "*"
                }
            },
            "@temporalio/client": {
                "peerDependencies": {
                    "@temporalio/common": "*",
                    "@temporalio/internal-non-workflow-common": "*",
                    "@temporalio/internal-workflow-common": "*",
                    "@temporalio/proto": "*"
                },
                "dependencies": {
                    "@types/long": "*"
                }
            },
            "@temporalio/common": {
                "peerDependencies": {
                    "@temporalio/internal-workflow-common": "*",
                    "@temporalio/proto": "*"
                }
            },
            "@temporalio/core-bridge": {
                "peerDependencies": {
                    "@temporalio/internal-non-workflow-common": "*"
                }
            },
            "@temporalio/interceptors-opentelemetry": {
                "peerDependencies": {
                    "@temporalio/client": "*",
                    "@temporalio/common": "*",
                    "@temporalio/worker": "*",
                    "@temporalio/workflow": "*"
                }
            },
            "@temporalio/internal-non-workflow-common": {
                "peerDependencies": {
                    "@temporalio/common": "*",
                    "@temporalio/internal-workflow-common": "*"
                },
                "dependencies": {
                    "@opentelemetry/api": "*"
                }
            },
            "@temporalio/internal-workflow-common": {
                "peerDependencies": {
                    "@temporalio/proto": "*"
                }
            },
            "@temporalio/testing": {
                "peerDependencies": {
                    "@temporalio/activity": "*",
                    "@temporalio/client": "*",
                    "@temporalio/common": "*",
                    "@temporalio/worker": "*",
                    "abort-controller": "*"
                }
            },
            "@temporalio/worker": {
                "peerDependencies": {
                    "@temporalio/activity": "*",
                    "@temporalio/common": "*",
                    "@temporalio/core-bridge": "*",
                    "@temporalio/internal-non-workflow-common": "*",
                    "@temporalio/internal-workflow-common": "*",
                    "@temporalio/proto": "*",
                    "@temporalio/workflow": "*",
                    "abort-controller": "*"
                }
            },
            "@temporalio/workflow": {
                "peerDependencies": {
                    "@temporalio/internal-workflow-common": "*",
                    "@temporalio/proto": "*",
                    "@temporalio/common": "*"
                }
            },
            "@grpc/grpc-js": {
                "dependencies": {
                    "@types/long": "*"
                }
            }
        }
    }

I’m planning to submit PRs to fix all of these in the near future, but don’t have much time to work on this right now. However, you can easily define similar overrides in your Yarn3 project. Too bad the syntax isn’t the same for PNPM vs Yarn3, but converting the above to Yarn3’s packageextensions shouldn’t be difficult. See Yarn’s documentation about this.

1 Like
nodeLinker: node-modules
nmHoistingLimits: none

adding this^ seemed to have fixed my problem

thanks!

hmm it looks like when i run the test adding that to my .yarnrc gives me some dependency issues:

Error: Cannot find module '@mikro-orm/mysql'
Require stack:
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/Configuration.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/index.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/types/JsonType.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/QueryHelper.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/entity/EntityLoader.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/entity/index.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/metadata/EntitySchema.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/metadata/index.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/MikroORM.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/core/index.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/nestjs/mikro-orm.module.js
- /Users/jackwang/scaleapi/node_modules/@mikro-orm/nestjs/index.js
- /Users/jackwang/scaleapi/packages/task-pipeline/dist/app.module.js
- /Users/jackwang/scaleapi/packages/task-pipeline/dist/temporal-test/temporal-pipeline-service-activities.js
- /Users/jackwang/scaleapi/packages/task-pipeline/dist/worker.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Module.Hook.Module.require (/Users/jackwang/scaleapi/node_modules/dd-trace/packages/dd-trace/src/ritm.js:51:29)
    at require (node:internal/modules/cjs/helpers:102:18)
    at module (/Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/Configuration.js:278:56)
    at Configuration.initDriver (/Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/Configuration.js:191:35)
    at new Configuration (/Users/jackwang/scaleapi/node_modules/@mikro-orm/core/utils/Configuration.js:33:28)
    at new MikroORM (/Users/jackwang/scaleapi/node_modules/@mikro-orm/core/MikroORM.js:17:27)
    at Function.init (/Users/jackwang/scaleapi/node_modules/@mikro-orm/core/MikroORM.js:40:21)
    at async Injector.instantiateClass (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/injector.js:305:37)
    at async callback (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/injector.js:48:30)
    at async Injector.resolveConstructorParams (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/injector.js:124:24)
    at async Injector.loadInstance (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/injector.js:52:9)
    at async Injector.loadProvider (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/injector.js:74:9)
    at async Promise.all (index 4)
    at async InstanceLoader.createInstancesOfProviders (/Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/instance-loader.js:44:9)
    at async /Users/jackwang/scaleapi/node_modules/@nestjs/core/injector/instance-loader.js:29:13

using this makes it work again:

nodeLinker: pnp
nmHoistingLimits: none
pnpMode: loose

kind of new to node so not super sure what’s going on here

kind of new to node so not super sure what’s going on here

I see… Yarn3 isn’t exactly the easiest way to begin with nodejs… It introduces huge changes that are are often incompatible with “traditional” package managers (npm and yarn classic).

I’m not arguing against it: Yarn3 and PNPM (another “new generation” package manager) both addresses real issues, and brings many advantages. But be warned that you are likely to face multiple dependencies issues…

So i realized that using

nodeLinker: pnp
nmHoistingLimits: none
pnpMode: loose

is very unideal for the rest of my project.

i am trying to explicitly define the peer dependencies like you suggested in my .yarnrc file:

packageExtensions:
  "@temporalio/activity@0.23.x":
    peerDependencies:
      "@temporalio/common": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
      "@temporalio/proto": "0.23.x"
      "abort-controller": "*"
  "@temporalio/client@0.23.x":
    peerDependencies:
      "@temporalio/common": "0.23.x"
      "@temporalio/internal-non-workflow-common": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
      "@temporalio/proto": "0.23.x"
    dependencies:
      "@types/long": "*"
  "@temporalio/common@0.23.x":
    peerDependencies:
      "@temporalio/proto": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
  "@temporalio/core-bridge@0.23.x":
    peerDependencies:
      "@temporalio/internal-non-workflow-common": "0.23.x"
  "@temporalio/interceptors-opentelemetry@0.23.x":
    peerDependencies:
      "@temporalio/client": "0.23.x"
      "@temporalio/common": "0.23.x"
      "@temporalio/worker": "0.23.x"
      "@temporalio/workflow": "0.23.x"
  "@temporalio/internal-non-workflow-common@0.23.x":
    peerDependencies:
      "@temporalio/common": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
  "@temporalio/internal-workflow-common@0.23.x":
    peerDependencies:
      "@temporalio/proto": "0.23.x"
    dependencies:
      "@types/long": "*"
  "@temporalio/worker@0.23.x":
    peerDependencies:
      "@temporalio/activity": "0.23.x"
      "@temporalio/common": "0.23.x"
      "@temporalio/core-bridge": "0.23.x"
      "@temporalio/internal-non-workflow-common": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
      "@temporalio/proto": "0.23.x"
      "@temporalio/workflow": "0.23.x"
      "abort-controller": "*"
  "@temporalio/workflow@0.23.x":
    dependencies:
      "@temporalio/common": "0.23.x"
    peerDependencies:
      "@temporalio/common": "0.23.x"
      "@temporalio/internal-workflow-common": "0.23.x"
      "@temporalio/proto": "0.23.x"
  "@grpc/grpc-js@1.6.x":
    dependencies:
      "@types/long": "*"

and i am still getting the same error

so i got this to work by adding:

    "long": "^5.2.0"

to the root package.json