这篇文章上次修改于 1037 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

问题:使用 create-next-app 创建项目,结果出现了报错,提示 No receipt for 'com.apple.pkg.CLTools_Executables' found

paul@PauldeiMac 项目 % npx create-next-app --typescript
✔ What is your project named? … next-app
Creating a new Next.js app in /Users/paul/Documents/项目/next-app.

Installing react, react-dom, and next using npm...

npm ERR! code 1
npm ERR! path /Users/paul/Documents/项目/next-app/node_modules/fibers
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
npm ERR! 
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
npm ERR! 
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
npm ERR! 
npm ERR! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/paul/Documents/项目/next-app/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:376:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:284:12)
npm ERR! gyp ERR! System Darwin 20.3.0
npm ERR! gyp ERR! command "/usr/local/Cellar/node/15.5.0/bin/node" "/Users/paul/Documents/项目/next-app/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/paul/Documents/项目/next-app/node_modules/fibers
npm ERR! gyp ERR! node -v v15.5.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

搜索了一下,需要更新 XCode Command Line Tools

MAC 下 npm install 报错...

sudo xcode-select -r

之后依然出现异常,只需要把我公司电脑的 XCode 打开一次激活就可以了... 比较好奇,为什么 NodeJS 要我 XCode?

npm ERR! code 1
npm ERR! path /Users/paul/Documents/项目/next-app/node_modules/fibers
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! You have not agreed to the Xcode license agreements, please run 'sudo xcodebuild -license' from within a Terminal window to review and agree to the Xcode license agreements.
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 69
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/paul/Documents/项目/next-app/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:376:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:284:12)
npm ERR! gyp ERR! System Darwin 20.3.0
npm ERR! gyp ERR! command "/usr/local/Cellar/node/15.5.0/bin/node" "/Users/paul/Documents/项目/next-app/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/paul/Documents/项目/next-app/node_modules/fibers
npm ERR! gyp ERR! node -v v15.5.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok