Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mn4367 opened this issue Mar 13, 2024 · 0 comments
Open

Comments

@mn4367
Copy link

mn4367 commented Mar 13, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant