下面是详细报错信息:
│ gyp ERR! build error
│ gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
│ gyp ERR! stack at ChildProcess.onExit (C:\Users\46917\AppData\Local\pnpm\global\5\.pnpm\pnpm@7.28.0\node_modules\pnpm\dist\node_modules\node-gyp\lib\build.js:203:23)
│ gyp ERR! stack at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:291:12)
│ gyp ERR! System Windows_NT 10.0.22621
│ gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\46917\\AppData\\Local\\pnpm\\global\\5\\.pnpm\\pnpm@7.28.0\\node_modules\\pnpm\\dist\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallb
│ gyp ERR! cwd C:\Users\46917\Desktop\items\mopo-code\node_modules\.pnpm\grpc@1.24.11\node_modules\grpc
│ gyp ERR! node -v v18.13.0
│ gyp ERR! node-gyp -v v9.3.1
│ gyp ERR! not ok
│ node-pre-gyp ERR! build error
│ node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\46917\AppData\Local\pnpm\global\5\.pnpm\pnpm@7.28.0\node_modules\pnpm\dist\node_modules\node-gyp\bin\node-gyp.js build
│ node-pre-gyp ERR! stack at ChildProcess.<anonymous> (C:\Users\46917\Desktop\items\mopo-code\node_modules\.pnpm\@mapbox+node-pre-gyp@1.0.10\node_modules\@mapbox\node-pre-gyp\lib\util\compile.js:89:23)
│ node-pre-gyp ERR! stack at ChildProcess.emit (node:events:513:28)
│ node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1091:16)
│ node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:302:5)
│ node-pre-gyp ERR! System Windows_NT 10.0.22621
│ node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\46917\\Desktop\\items\\mopo-code\\node_modules\\.pnpm\\@mapbox+node-pre-gyp@1.0.10\\node_modules\\@mapbox\\node-pre-gyp\\bin\\node-pre-
│ node-pre-gyp ERR! cwd C:\Users\46917\Desktop\items\mopo-code\node_modules\.pnpm\grpc@1.24.11\node_modules\grpc
│ node-pre-gyp ERR! node -v v18.13.0
│ node-pre-gyp ERR! node-pre-gyp -v v1.0.10
│ node-pre-gyp ERR! not ok
│ Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\46917\AppData\Local\pnpm\global\5\.pnpm\pnpm@7.28.0\node_modules\pnpm\dist\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --library=s
└─ Failed in 3m 14.9s at C:\Users\46917\Desktop\items\mopo-code\node_modules\.pnpm\grpc@1.24.11\node_modules\grpc
node_modules/.pnpm/turbo@1.6.3/node_modules/turbo: Running postinstall script, done in 654ms
ELIFECYCLE Command failed with exit code 1.
每次创建新项目的时候我都会被老项目里的grpc框架折磨,每次被折磨完之后又会感觉好像这么简单的问题也没必要记录,然后下一次创建项目的时候又被折磨,周而复始,最后还是下决心记录一下这个问题。
报错原因很简单,让我们来看到这一段:
│ gyp ERR! node -v v18.13.0
│ gyp ERR! node-gyp -v v9.3.1
你可以试试是不是node版本和node-gyp版本不匹配导致的,具体怎么查匹配版本我忘记了,总之先试一下他们都在说的最稳定的 14.17.1
版本吧。
npm i -g nvm 下载一个node版本管理工具
nvm list 可以看到当前已下载的node版本
nvm install 14.17.1 下载对应版本
nvm use 14.17.1 使用对应版本
我的报错就解决了。