Skip to content

Error on import inside worker module #22

@fmerg

Description

@fmerg

I have a CPU intensive operation over JubJub, which I want to split into parallel tasks and offload to different worker threads. Each worker needs a eddsa instance to work with. My context does not allow for shared memory among workers and transferring eddsa to the worker threads is also not possible in any feasible way. I would like each worker to create its own eddsa instance:

const circomlibjs = require('circomlibjs');
...
const eddsa = await circomlibjs.buildEddsa();

However, importing circomlibjs inside the worker module raises an error when the worker starts running:

TypeError: Cannot destructure property 'mod' of 'threads.workerData' as it is undefined.

  at workerThread (node_modules/web-worker/cjs/node.js:151:5)
  at Object.<anonymous> (node_modules/web-worker/cjs/node.js:79:56)
  at Object.<anonymous> (node_modules/circomlibjs/node_modules/ffjavascript/build/main.cjs:8:14)

The exact error depends on the multithreading library in use. The above one is raised with workerpool. If I use the native node:worker_threads or web workers for the browser, I get something like

TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:399:5)
    at validateString (node:internal/validators:163:11)
    at Module.require (node:internal/modules/cjs/loader:1120:3)
    at require (node:internal/modules/helpers:112:18)
    ...
    at Module.load (node:internal/modules/cjs/loader:1103:32) {
  code: 'ERR_INVALID_ARG_TYPE'

I do not face import issues with other libraries. I wonder if this is my fault (that is, if circomlibjs should be imported in a different way inside js threads) or a bug.

Any idea or hint is welcome. Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions