❯ npm i -g yarn internal/modules/cjs/loader.js:934 throw err; ^
Error: Cannot find module '../lib/utils/unsupported.js' Require stack: - /Users/admin/.nvm/versions/node/v14.999.999/bin/npm at Function.Module._resolveFilename (internal/modules/cjs/loader.js:931:15) at Function.Module._load (internal/modules/cjs/loader.js:774:27) at Module.require (internal/modules/cjs/loader.js:1003:19) at require (internal/modules/cjs/helpers.js:107:18) at /Users/admin/.nvm/versions/node/v14.999.999/bin/npm:19:21 at Object.<anonymous> (/Users/admin/.nvm/versions/node/v14.999.999/bin/npm:155:3) at Module._compile (internal/modules/cjs/loader.js:1114:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10) at Module.load (internal/modules/cjs/loader.js:979:32) at Function.Module._load (internal/modules/cjs/loader.js:819:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/admin/.nvm/versions/node/v14.999.999/bin/npm' ] }
解决方法
重新指定 ./configure --prefix= 到 ~/.nvm/versions/node/v14.999.999 目录,再 make install 即可
故障原因
copy 到 .nvm 目录的过程中丢失了软连接,导致 node 寻找依赖的逻辑不符合预期
1 2 3 4 5 6 7 8 9 10
[~/.nvm/versions/node/v14.999.999/bin]❯ l total 136352 drwxr-xr-x 8 admin staff 256B Jun 5 15:24 . drwxr-xr-x 6 admin staff 192B Jun 5 15:25 .. -rwxr-xr-x 1 admin staff 600K Jun 5 15:24 corepack -rwxr-xr-x 1 admin staff 66M Jun 5 15:24 node -rwxr-xr-x 1 admin staff 4.6K Jun 5 15:24 npm -rwxr-xr-x 1 admin staff 177B Jun 5 15:24 npx -rwxr-xr-x 1 admin staff 8.1K Jun 5 15:24 tnpm -rwxr-xr-x 1 admin staff 309B Jun 5 15:24 tnpx
这个目录正确的应该如下
1 2 3 4 5 6 7 8 9 10
[~/workspace/prebuild-node/v14.21.3/bin]❯ l total 135096 drwxr-xr-x 8 admin staff 256B Jun 5 11:23 . drwxr-xr-x 6 admin staff 192B Jun 5 11:01 .. lrwxr-xr-x 1 admin staff 45B Jun 5 11:01 corepack -> ../lib/node_modules/corepack/dist/corepack.js -rwxr-xr-x 1 admin staff 66M Jun 5 11:01 node lrwxr-xr-x 1 admin staff 38B Jun 5 11:01 npm -> ../lib/node_modules/npm/bin/npm-cli.js lrwxr-xr-x 1 admin staff 38B Jun 5 11:01 npx -> ../lib/node_modules/npm/bin/npx-cli.js lrwxr-xr-x 1 admin staff 36B Jun 5 11:23 tnpm -> ../lib/node_modules/tnpm/bin/tnpm.js lrwxr-xr-x 1 admin staff 36B Jun 5 11:23 tnpx -> ../lib/node_modules/tnpm/bin/tnpx.js
1 #!/usr/bin/env node 2 ;(function () { // wrapper in case we're in module_context mode 3// windows: running "npm blah" in this folder will invoke WSH, not node. 4/* global WScript */ 5if (typeofWScript !== 'undefined') { 6WScript.echo( 7'npm does not work when run\n' + 8'with the Windows Scripting Host\n\n' + 9"'cd' to a different directory,\n" + 10"or type 'npm.cmd <args>',\n" + 11"or type 'node npm <args>'." 12 ) 13WScript.quit(1) 14return 15 } 16 17 process.title = 'npm' 18 19var unsupported = require('../lib/utils/unsupported.js') // <<-------------- 20 unsupported.checkForBrokenNode()