Skip to content

Loading worker thread js file while using patchRequire and patchFs failed #1008

@mn4367

Description

@mn4367

This is more a question than an issue.

I've created and saved a binary snapshot from a directory with a bunch of JavaScript code. After deleting this source code directory I'm loading the snapshot into a memory filesystem which then got patched with patchRequire. In the next step I created a union file system from the memory filesystem together with the regular node fs. In the last step I patched this union filesystem with patchFs. That worked without any problems so far and enabled me to load and execute an app from a single binary file without the original source code.

Then I modified the source code so that it makes use of a worker thread which is also contained in the binary snapshot file. This results in the following error:

node:internal/event_target:1096
  process.nextTick(() => { throw err; });
                           ^
Error: Cannot find module '/Users/johndoe/repos/test_memfs/WorkerThread.js'
    at Function._resolveFilename (node:internal/modules/cjs/loader:1142:15)
    at Function._load (node:internal/modules/cjs/loader:983:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:822:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Tested on Node.js v21.7.1 with fs-monkey 1.0.5, memfs 4.7.7 and unionfs 4.5.1. The test machine is a Mac with M1 chip running Ventura 13.6.4.

Can somebody confirm that it is impossible to load a worker thread source code file from a memory filesystem? Maybe there are any workarounds?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions