Skip to content

Native modules don't work in worker threads using sea #293

Description

@ronisaacson

What version of pkg are you using?

6.22.0

What version of Node.js are you using?

24.19.0

What operating system are you using?

Windows (using git bash)

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node24-win32-x64

Describe the Bug

Following up on #292, I tried switching to sea, but now I have a different problem! I I'm using a package with a native module (roaring). I'm using worker threads, and trying to use roaring from the worker threads. I'm using tinypool to manage the workers.

After packaging with sea, roaring works fine when loaded from the main thread, and tinypool is able to spawn worker threads. But the worker threads can't use roaring:

Error: The specified module could not be found.
\\?\C:\snapshot\test\node_modules\roaring\native\roaring-node-v137-win32-x64-unknown\roaring.node
    at Object..node (node:internal/modules/cjs/loader:2030:18)
    at Module.load (node:internal/modules/cjs/loader:1594:32)
    at Module._load (node:internal/modules/cjs/loader:1396:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
    at Module.require (node:internal/modules/cjs/loader:1617:12)
    at require (node:internal/modules/helpers:153:16)
    at C:\snapshot\test\node_modules\roaring\index.js:34:12
    at Object.<anonymous> (C:\snapshot\test\node_modules\roaring\index.js:43:3)
    at Module._compile (node:internal/modules/cjs/loader:1872:14)
    at NodeModule._extensions..js ([worker eval]:3154:21) {
  code: 'ERR_DLOPEN_FAILED'
}

I added some logging to the pkg boostrap, and best I can tell, patchDlopen() never gets called by the worker thread. It's called by sea-bootstrap-core, but it's not called again inside workerBootstrap.

This works correctly using legacy (non-sea).

Expected Behavior

Worker threads should be able to use native modules

To Reproduce

See above

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