记一次tc-chat-demo-electron历史项目维护

333 阅读1分钟

windows系统

1. 确定node版本

查看electron,electron-builder,node-gypnpm依赖包对node版本要求,通过nvm安装对应版本的node

2. node-gyp

查看官网地址

  • 2.1. 安装Python,并设置环境变量

安装的Python版本对node-gyp版本有要求,比如:Python >= v3.12 requires node-gyp >= v10

py --list-paths  # To see the installed Python versions
set npm_config_python=C:\path\to\python.exe  # CMD
$Env:npm_config_python="C:\path\to\python.exe"  # PowerShell

安装完以后执行以下命令:

node-gyp list
node-gyp install
# 2022版本是你安装的vs版本
node-gyp configure --msvs_version=2022
pip install setuptools

3. 代理

npm install构建之前需配置代理,否则会出现构建失败

# clash for windows on Windows PowerShell
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"
# clash for windows on Windows cmd
set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890

4. npm安装构建

npm install
electron-builder -w

Mac OS

安装python

安装以后,设置环境变量

# 添加到 ~/.zshrc
export PATH=/Library/Frameworks/Python.framework/Versions/3.13/bin/python3

# 对于 Zsh
source ~/.zshrc

# 验证
which python3
python3 --version

# 使用特定版本python3
export npm_config_python=$(which python3)

# https://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi
pip3 install setuptools --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org

打包构建错误处理

⨯ Exit code: 1. Command failed: /Library/Frameworks/Python.framework/Versions/3.13/bin/python3 /Users/yangjunhua/Projects/moushi/im/node_modules/dmg-builder/vendor/dmgbuild/core.py

Traceback (most recent call last):

image.png

解决:electron-builder@22.11.7不支持python3.13,更新到最新版本23.6.0(支持node@14.17)