Electron打包
使用Electron的 electron-builder 进行打包。提供 windows、linux 、mac 平台下的安装包。
安装nvm
使用第三方工具像 nvm(Node Version Manager)来安装和管理不同版本的 Node.js。nvm 允许您轻松地在同一系统上切换不同的 Node.js 版本。
以下是使用 nvm 安装 Node.js 14 的步骤:
- 在终端中运行以下命令,通过 cURL 安装 NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
或
curl -o- https://raw.fastgit.org/nvm-sh/nvm/v0.39.0/install.sh | bash
或者,如果您更喜欢使用 wget,可以运行以下命令:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
或
wget -qO- https://raw.staticdn.net/nvm-sh/nvm/v0.39.0/install.sh | bash
- 安装完成后,关闭并重新打开终端,以便使 NVM 生效。
- 使用 NVM 安装 Node.js 20。在终端中运行以下命令:
nvm install 20
这将下载并安装 Node.js 20 版本。
- 安装完成后,您可以使用以下命令验证 Node.js 是否成功安装:
node -v
Node.js 版本管理
- 查看所有Node.js版本:
nvm ls
- 卸载 Node.js :
nvm uninstall 20
- 切换 Node.js版本:
nvm use 20
安装wine
windows打包需要使用,安装命令:
brew install wine
nodejs配置镜像
Electron 安装库的时候,有很多下载不了或者卡住。添加全局的镜像仓库:
-
打开
.npmrcvim ~/.npmrc -
添加镜像:
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
打包electron应用
当前使用的是Node.js 20版本
-
打包
Windows平台:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --win --x64 -
打包
Mac平台x64架构:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --mac --x64 -
打包
Mac平台arm64架构:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --mac --arm64 -
打包
Linux平台deb架构:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --linux --x64 deb -
打包
Linux平台rpm架构:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build --linux --x64 rpm -
打包
全部平台x85:export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service electron:build -mwl --x64
-mwl:为macOS,Windows和Linux构建(同时构建)
commands(命令):
electron-builder build 构建命名 [default]
electron-builder install-app-deps 下载app依赖
electron-builder node-gyp-rebuild 重建自己的本机代码
electron-builder create-self-signed-cert 为Windows应用程序创建自签名代码签名证书
electron-builder start 使用electronic-webpack在开发模式下运行应用程序(须臾要 electron-webpack模块支持)
Building(构建参数):
--mac, -m, -o, --macos Build for macOS, [array]
--linux, -l Build for Linux [array]
--win, -w, --windows Build for Windows [array]
--x64 Build for x64 (64位安装包) [boolean]
--ia32 Build for ia32(32位安装包) [boolean]
--armv7l Build for armv7l [boolean]
--arm64 Build for arm64 [boolean]
--dir Build unpacked dir. Useful to test. [boolean]
--prepackaged, --pd 预打包应用程序的路径(以可分发的格式打包)
--projectDir, --project 项目目录的路径。 默认为当前工作目录。
--config, -c 配置文件路径。 默认为`electron-builder.yml`(或`js`,或`js5`)
Examples(例子):
electron-builder -mwl 为macOS,Windows和Linux构建(同时构建)
electron-builder --linux deb tar.xz 为Linux构建deb和tar.xz
electron-builder -c.extraMetadata.foo=bar 将package.js属性`foo`设置为`bar`
electron-builder --config.nsis.unicode=false 为NSIS配置unicode选项
切换npm源
- 使用以下命令安装
nrm
npm install -g nrm
- 使用以下命令查看可用的 NPM 源:
nrm ls
- 使用以下命令切换到其他 NPM 源,例如淘宝源:
nrm use taobao
npm设置代理
使用代理:如果您使用代理服务器访问互联网,请确保 NPM 可以正确配置代理。可以使用以下命令配置 NPM 代理:
- HTTP 代理:
npm config set proxy http://proxy.example.com:8080 - HTTPS 代理:
npm config set https-proxy http://proxy.example.com:8080
Docker打包
目前官方的Docker只能打包windows/linux 的安装包。Mac安装包目前不能使用docker打包,需要在 Mac系统上才可以进行。全平台的安装包打包
-
下载官方镜像:
docker pull electronuserland/builder:wine
-
运行官方
docker镜像:docker run -it -d --name electron-build --restart=always electronuserland/builder:wine
问题一:
Error: Exit code: ENOENT. spawn /usr/local/bin/python3 ENOENT
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/builder-util/src/util.ts:133:18
at exithandler (node:child_process:430:5)
at ChildProcess.errorhandler (node:child_process:442:5)
at ChildProcess.emit (node:events:514:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
原因:当前系统不支持 python2.7版本。package-lock.json文件中 "electron-builder": "^22.2.0" 只支持python2
解决方案:
- 把
electron-builder版本提高到23.0.3版本及以上 - 删除当前缓存文件
rm -rf node_modules
rm -rf dist
rm -rf package-lock.json
- 重新编译
npm install
如果还是不行。可以重启
idea工具
查看npm的依赖关系:
npm list electron-builder
yuhang@yuhangs-MacBook-Pro ~/yuyue/project/webstorm/hd-fh-screenpush master ± npm list electron-builder
fh-screen-push@2023.09.04 /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush
├── electron-builder@24.9.1 overridden
└─┬ vue-cli-plugin-electron-builder@2.1.1 overridden
└── electron-builder@24.9.1 deduped
问题二
ERROR Failed to compile with 1 errors 5:31:54 PM
error
background.js from Terser
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:68:19)
at Object.createHash (node:crypto:138:10)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/node_modules/terser-webpack-plugin/dist/index.js:217:37
at Array.forEach (<anonymous>)
at TerserPlugin.optimizeFn (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/node_modules/terser-webpack-plugin/dist/index.js:160:259)
at _next0 (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:8:1)
at eval (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:23:1)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/index.js:198
throw new Error('Build failed with errors.')
^
Error: Build failed with errors.
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/index.js:198:21
at finalCallback (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compiler.js:257:39)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compiler.js:273:13
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at AsyncSeriesHook.lazyCompileHook (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/Hook.js:154:20)
at onCompiled (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compiler.js:271:21)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compiler.js:681:15
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/Hook.js:154:20)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compiler.js:678:31
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/Hook.js:154:20)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compilation.js:1423:35
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/Hook.js:154:20)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/lib/Compilation.js:1414:32
at eval (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
at /Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/node_modules/terser-webpack-plugin/dist/index.js:321:9
at TaskRunner.run (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/node_modules/terser-webpack-plugin/dist/TaskRunner.js:48:7)
at TerserPlugin.optimizeFn (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/webpack/node_modules/terser-webpack-plugin/dist/index.js:227:18)
at _next0 (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:8:1)
at eval (eval at create (/Users/yuhang/yuyue/project/webstorm/hd-fh-screenpush/node_modules/vue-cli-plugin-electron-builder/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:23:1)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.10.0
原因:node.js 使用20的版本。
解决方案:执行 electron:build 之前 添加环境变量:
export NODE_OPTIONS=--openssl-legacy-provider
低版本的node.js 不需要。不需要忽略 ssl 验证
问题三
linux系统上打包。报错:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE current: { node: 'v20.10.0', npm: '10.2.3' }
npm WARN EBADENGINE }
> fh-screen-push@2023.09.04 postinstall
> electron-builder install-app-deps
• electron-builder version=23.6.0
• rebuilding native dependencies dependencies=canvas@2.11.2 platform=linux arch=x64
⨯ cannot execute cause=exit status 1
errorOut=npm ERR! code 1
npm ERR! path /project/hd-fh-screenpush/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build --update-binary
npm ERR! Failed to execute '/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v25.9' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.11
npm ERR! node-pre-gyp info using node@20.10.0 | linux | x64
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and electron@25.9.8 (electron-v25.9 ABI, glibc) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@10.0.1
npm ERR! gyp info using node@20.10.0 | linux | x64
npm ERR! gyp info ok
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@10.0.1
npm ERR! gyp info using node@20.10.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "/usr/bin/python3"
npm ERR! gyp http GET https://electronjs.org/headers/v25.9.8/node-v25.9.8-headers.tar.gz
npm ERR! gyp http 200 https://artifacts.electronjs.org/headers/v25.9.8/node-v25.9.8-headers.tar.gz?force_headers_dist=1
npm ERR! gyp http GET https://electronjs.org/headers/v25.9.8/SHASUMS256.txt
npm ERR! gyp http 200 https://artifacts.electronjs.org/headers/v25.9.8/SHASUMS256.txt?force_headers_dist=1
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/project/hd-fh-screenpush/node_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/root/.electron-gyp/25.9.8/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/root/.electron-gyp/25.9.8',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/root/.electron-gyp/25.9.8/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/project/hd-fh-screenpush/node_modules/canvas',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Package pixman-1 was not found in the pkg-config search path.
npm ERR! Perhaps you should add the directory containing `pixman-1.pc'
npm ERR! to the PKG_CONFIG_PATH environment variable
npm ERR! No package 'pixman-1' found
npm ERR! gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.<anonymous> (/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:271:18)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:514:28)
npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Linux 5.15.0-88-generic
npm ERR! gyp ERR! command "/root/.nvm/versions/node/v20.10.0/bin/node" "/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=electron-v25.9"
npm ERR! gyp ERR! cwd /project/hd-fh-screenpush/node_modules/canvas
npm ERR! gyp ERR! node -v v20.10.0
npm ERR! gyp ERR! node-gyp -v v10.0.1
npm ERR! gyp ERR! not ok
npm ERR! node-pre-gyp ERR! build error
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v25.9' (1)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/project/hd-fh-screenpush/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:514:28)
npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1105:16)
npm ERR! node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:305:5)
npm ERR! node-pre-gyp ERR! System Linux 5.15.0-88-generic
npm ERR! node-pre-gyp ERR! command "/root/.nvm/versions/node/v20.10.0/bin/node" "/project/hd-fh-screenpush/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
npm ERR! node-pre-gyp ERR! cwd /project/hd-fh-screenpush/node_modules/canvas
npm ERR! node-pre-gyp ERR! node -v v20.10.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.11
npm ERR! node-pre-gyp ERR! not ok
npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-12-27T08_12_16_041Z-debug-0.log
command=/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/bin/npm-cli.js rebuild canvas@2.11.2
workingDir=
npm ERR! code 1
npm ERR! path /project/hd-fh-screenpush
npm ERR! command failed
npm ERR! command sh -c electron-builder install-app-deps
原因:由于安装canvas模块时出现了问题。根据日志信息,可能的原因是缺少pixman-1库
-
确保你的操作系统上已经安装了pixman-1库。你可以尝试通过以下命令来安装它:
apt-get install libpixman-1-dev
-
如果已经安装了pixman-1库,可以尝试将其路径添加到PKG_CONFIG_PATH环境变量中。使用以下命令:
vim ~/.bashrc
-
加入配置:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
-
生效:
source ~/.bashrc
-
然后,尝试重新安装canvas模块。在项目目录下执行以下命令:
npm rebuild canvas@2.11.2
有时候是缓存问题,把缓存清空再重新编译。清空命令:
rm -rf node_modules && rm -rf package-lock.json && npm install
问题四
在linux系统中打包报错:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE current: { node: 'v20.10.0', npm: '10.2.3' }
npm WARN EBADENGINE }
npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead
npm WARN deprecated domexception@1.0.1: Use your platform's native DOMException instead
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated asar@3.2.0: Please use @electron/asar moving forward. There is no API change, just a package name change
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated electron-osx-sign@0.6.0: Please use @electron/osx-sign moving forward. Be aware the API is slightly different
npm WARN deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
> fh-screen-push@2023.09.04 postinstall
> electron-builder install-app-deps
• electron-builder version=23.6.0
• rebuilding native dependencies dependencies=canvas@2.11.2 platform=linux arch=x64
⨯ cannot execute cause=exit status 1
errorOut=npm ERR! code 1
npm ERR! path /project/hd-fh-screenpush/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build --update-binary
npm ERR! Failed to execute '/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v25.9' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using node-pre-gyp@1.0.11
npm ERR! node-pre-gyp info using node@20.10.0 | linux | x64
npm ERR! node-pre-gyp http GET https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz
npm ERR! node-pre-gyp ERR! install request to https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz failed, reason: socket hang up
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.2 and electron@25.9.8 (electron-v25.9 ABI, glibc) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp WARN Hit error request to https://github.com/Automattic/node-canvas/releases/download/v2.11.2/canvas-v2.11.2-electron-v25.9-linux-glibc-x64.tar.gz failed, reason: socket hang up
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@10.0.1
npm ERR! gyp info using node@20.10.0 | linux | x64
npm ERR! gyp info ok
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@10.0.1
npm ERR! gyp info using node@20.10.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "/usr/bin/python3"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/project/hd-fh-screenpush/node_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/root/.electron-gyp/25.9.8/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/root/.electron-gyp/25.9.8',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/root/.electron-gyp/25.9.8/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/project/hd-fh-screenpush/node_modules/canvas',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! Package cairo was not found in the pkg-config search path.
npm ERR! Perhaps you should add the directory containing `cairo.pc'
npm ERR! to the PKG_CONFIG_PATH environment variable
npm ERR! No package 'cairo' found
npm ERR! gyp: Call to 'pkg-config cairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.<anonymous> (/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:271:18)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:514:28)
npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Linux 5.15.0-88-generic
npm ERR! gyp ERR! command "/root/.nvm/versions/node/v20.10.0/bin/node" "/root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=electron-v25.9"
npm ERR! gyp ERR! cwd /project/hd-fh-screenpush/node_modules/canvas
npm ERR! gyp ERR! node -v v20.10.0
npm ERR! gyp ERR! node-gyp -v v10.0.1
npm ERR! gyp ERR! not ok
npm ERR! node-pre-gyp ERR! build error
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/project/hd-fh-screenpush/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/project/hd-fh-screenpush/node_modules/canvas/build/Release --napi_version=9 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=electron-v25.9' (1)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/project/hd-fh-screenpush/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:514:28)
npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1105:16)
npm ERR! node-pre-gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:305:5)
npm ERR! node-pre-gyp ERR! System Linux 5.15.0-88-generic
npm ERR! node-pre-gyp ERR! command "/root/.nvm/versions/node/v20.10.0/bin/node" "/project/hd-fh-screenpush/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
npm ERR! node-pre-gyp ERR! cwd /project/hd-fh-screenpush/node_modules/canvas
npm ERR! node-pre-gyp ERR! node -v v20.10.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.11
npm ERR! node-pre-gyp ERR! not ok
npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-12-27T08_28_23_647Z-debug-0.log
command=/root/.nvm/versions/node/v20.10.0/bin/node /root/.nvm/versions/node/v20.10.0/lib/node_modules/npm/bin/npm-cli.js rebuild canvas@2.11.2
workingDir=
npm ERR! code 1
npm ERR! path /project/hd-fh-screenpush
npm ERR! command failed
npm ERR! command sh -c electron-builder install-app-deps
原因:这个错误是由于缺少canvas模块的依赖项所致。根据错误日志显示,缺少cairo库。
解决方案:
-
确保您已经安装了cairo库的依赖项。您可以使用以下命令来安装cairo库:
apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++