Error: Cannot find module 'npm-prefix.js'
When I specify `.prototools` versions for both npm and Node, `moon run <task>` runs with a PATH that looks like this:
```
PATH=$HOME/.proto/tools/npm/11.6.1/bin:$HOME/.proto/tools/node/24.9.0/bin:<...>
```
I can reproduce the error outside Moon:
```bash
$ PATH=$HOME/.proto/tools/npm/11.6.1/bin:$HOME/.proto/tools/node/24.9.0/bin:$PATH npm -v
node:internal/modules/cjs/loader:1423
throw err;
^
Error: Cannot find module '<HOME>/.proto/tools/node/24.9.0/bin/node_modules/npm/bin/npm-prefix.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1420:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1058:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1063:22)
at Module._load (node:internal/modules/cjs/loader:1226:37)
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
at node:internal/main/run_main_module:33:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v24.9.0
Could not determine Node.js install directory
```
The shim at `$HOME/.proto/tools/npm/11.6.1/bin/npm` detects the path to that file as:
```
basedir=`dirname "$0"` # ~/.proto/tools/npm/11.6.1/bin
NODE_EXE="$basedir/node" # ~/.proto/tools/npm/11.6.1/bin/node
CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)" # ~/.proto/tools/node/24.9.0/bin
NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
```
As a workaround, if I remove npm version from `.prototools`, it uses the version bundled with Node, which runs correctly.
I'm using Moon 1.41.6 on macOS 26.1. The same seems to happen with Moon 1.41.7 installed through Proto.
关闭于 2026-03-04 3 条评论