mirrord: npm module not found when running turbo app

Bug Description

Getting module not found when running some npm applications.

Seems like it could be related to #1956 and #1957, as we’re getting the same error.

What is happening is that node is looking for module in a location that is relative to a path in our temp dir, but we want it to look for modules relative to the original path. Not sure why our protections for that (hooking _NSGetExecutablePath, passing non-patched paths in exec args) did not prevent this. Maybe now the exec path is retrieved in a different way.

Volta-installed node is SIP-protected, unlike most node installations we’ve seen so far. I think this might be related to this issue.

Steps to Reproduce

git clone git@github.com:t4lz/mirrord-sip-npm-issue.git
cd mirrord-sip-npm-issue

you might have to install vollta and then install npm and npx via vollta at this point.

npm run repro

Backtrace

│ node:internal/modules/cjs/loader:1148
│   throw err;
│   ^
│ 
│ Error: Cannot find module '../lib/cli.js'
│ Require stack:
│ - /private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm
│     at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
│     at Module._load (node:internal/modules/cjs/loader:986:27)
│     at Module.require (node:internal/modules/cjs/loader:1233:19)
│     at require (node:internal/modules/helpers:179:18)
│     at Object.<anonymous> (/private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm:2:1)
│     at Module._compile (node:internal/modules/cjs/loader:1358:14)
│     at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
│     at Module.load (node:internal/modules/cjs/loader:1208:32)
│     at Module._load (node:internal/modules/cjs/loader:1024:12)
│     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12) {
│   code: 'MODULE_NOT_FOUND',
│   requireStack: [
│     '/private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm'
│   ]
│ }
│ 
│ Node.js v20.14.0
└────>
┌ web#dev > cache bypass, force executing acec579587217658 
│ 2024-06-06T17:55:53.106830Z TRACE ThreadId(16) mirrord_layer::file::hooks: path Success(
│     "/dev/fd",
│ ) | open_options OpenOptionsInternal {
│     read: true,
│     write: false,
│     append: false,
│     truncate: false,
│     create: false,
│     create_new: false,
│ }
│ 2024-06-06T17:55:53.106950Z TRACE ThreadId(16) mirrord_layer::exec_utils: Executable /Users/tal/Documents/projects/test_projects/volta_test/my-turborepo/node_modules/turbo-darwin-arm64/bin/turbo called execve/posix_spawn
│ 2024-06-06T17:55:53.107190Z TRACE ThreadId(16) mirrord_sip::main: Using existing SIP-patched version of "/usr/bin/env": "/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/usr/bin/env"
│ 2024-06-06T17:55:53.107199Z TRACE ThreadId(16) mirrord_sip::main: Shebang points to: "/usr/bin/env". Patching the interpreter and making a version of "/Users/tal/.volta/tools/image/node/20.14.0/bin/npm" with an altered shebang 
│ at: "/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm"
│ 2024-06-06T17:55:53.107328Z TRACE ThreadId(16) mirrord_layer::exec_utils: exec arg: /Users/tal/.volta/tools/image/node/20.14.0/bin/npm
│ 2024-06-06T17:55:53.107331Z TRACE ThreadId(16) mirrord_layer::exec_utils: exec arg: run
│ 2024-06-06T17:55:53.107333Z TRACE ThreadId(16) mirrord_layer::exec_utils: exec arg: dev
│ node:internal/modules/cjs/loader:1148
│   throw err;
│   ^
│ 
│ Error: Cannot find module '../lib/cli.js'
│ Require stack:
│ - /private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm
│     at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
│     at Module._load (node:internal/modules/cjs/loader:986:27)
│     at Module.require (node:internal/modules/cjs/loader:1233:19)
│     at require (node:internal/modules/helpers:179:18)
│     at Object.<anonymous> (/private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm:2:1)
│     at Module._compile (node:internal/modules/cjs/loader:1358:14)
│     at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
│     at Module.load (node:internal/modules/cjs/loader:1208:32)
│     at Module._load (node:internal/modules/cjs/loader:1024:12)
│     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12) {
│   code: 'MODULE_NOT_FOUND',
│   requireStack: [
│     '/private/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm'
│   ]
│ }
│ 
│ Node.js v20.14.0
│ command finished with error: command (/Users/tal/Documents/projects/test_projects/volta_test/my-turborepo/apps/web) /Users/tal/.volta/tools/image/node/20.14.0/bin/npm run dev exited (1)
└────>
 ERROR  run failed: command  exited (1)

Relevant Logs

│ 2024-06-06T17:55:53.105024Z TRACE ThreadId(15) mirrord_layer::exec_utils: Executable /Users/tal/Documents/projects/test_projects/volta_test/my-turborepo/node_modules/turbo-darwin-arm64/bin/turbo called execve/posix_spawn
│ 2024-06-06T17:55:53.105276Z TRACE ThreadId(15) mirrord_sip::main: Using existing SIP-patched version of "/usr/bin/env": "/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/usr/bin/env"
│ 2024-06-06T17:55:53.105289Z TRACE ThreadId(15) mirrord_sip::main: Shebang points to: "/usr/bin/env". Patching the interpreter and making a version of "/Users/tal/.volta/tools/image/node/20.14.0/bin/npm" with an altered shebang 
│ at: "/var/folders/4l/810mmn597cx7zy5w2bk11clh0000gn/T/mirrord-bin/Users/tal/.volta/tools/image/node/20.14.0/bin/npm"
│ 2024-06-06T17:55:53.105867Z TRACE ThreadId(15) mirrord_layer::exec_utils: exec arg: /Users/tal/.volta/tools/image/node/20.14.0/bin/npm
│ 2024-06-06T17:55:53.105872Z TRACE ThreadId(15) mirrord_layer::exec_utils: exec arg: run
│ 2024-06-06T17:55:53.105874Z TRACE ThreadId(15) mirrord_layer::exec_utils: exec arg: dev

Your operating system and version

MacOS 14.5

Local process

npm, node, turbo

Local process version

No response

Additional Info

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

perhaps add DYLD_INSERT_LIBRARIES as well? and add to mirrord.dev?