MacBook M1 更新Ventura后electron-forge错误的解决方案

目录 运维

最近将MacBook M1更新到Ventura 13.0.1版本,突然发现electron-forge无法运行了。出现以下的错误:

> rvbuild@1.0.0 start
> electron-forge start

⚠ Checking your system
  ✖ Could not find git in environment
  ✔ Found node@16.13.2
  ✔ Found npm@8.1.2

It looks like you are missing some dependencies you need to get Electron running.
Make sure you have git installed and Node.js version >= 14.17.5

开始以为是nodejs版本过低,直接安装最新版本的nodejs。再次执行

✔ Checking your system
It looks like you are missing some dependencies you need to get Electron running.
Make sure you have git installed and Node.js version 6.0.0+

一头雾水,回想起以前本本更新git都会出现问题,于是试探性去执行了下git -v

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

看样子问题就在这个xcrun了。执行xcode-select –install

MacBook-Pro ~ % xcode-select --install
xcode-select: note: install requested for command line developer tools

完成后再次测试git

git -v
git version 2.37.1 (Apple Git-137.1)

尝试执行electron-forge

> rvbuild@1.0.0 start
> electron-forge start

✔ Checking your system
✖ Locating Application

Electron forge was terminated:
You must depend on "electron-prebuilt-compile" in your devDependencies

删除项目node_modules文件,重新执行npm i,安装完成后便可以运行。

MacBook-Pro demo % npm run start

> rvbuild@1.0.0 start
> electron-forge start

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [1s]
✔ Running generateAssets hook