🎈 【Electron-builder 异常解决】gyp: name 'openssl_fips' is not defined …
0. 环境
Platform: linux Arch: x86_64
1. 异常
shellCopy
> application@3.1.5 package-lin /app/application
> tsc && electron-builder --linux
• electron-builder version=23.6.0 os=5.15.80-200.el7.x86_64
• loaded configuration file=package.json ("build" field)
• electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies
To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`
• writing effective config file=release/builder-effective-config.yaml
• rebuilding native dependencies dependencies=ffi-napi@4.0.3, ref-napi@3.0.3, ref-napi@3.0.3 platform=linux arch=arm64
⨯ cannot execute cause=exit status 1
out=
> ffi-napi@4.0.3 install /app/application/node_modules/_ffi-napi@4.0.3@ffi-napi
> node-gyp-build
errorOut=gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/app/application/node_modules/_node-gyp@9.4.1@node-gyp/lib/configure.js:325:16)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12)
gyp ERR! System Linux 5.15.80-200.el7.x86_64
gyp ERR! command "/usr/local/bin/node" "/app/application/node_modules/_node-gyp@9.4.1@node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /app/application/node_modules/_ffi-napi@4.0.3@ffi-napi
gyp ERR! node -v v14.19.3
gyp ERR! node-gyp -v v9.4.1
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ffi-napi@4.0.3 install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ffi-napi@4.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-11-24T08_15_40_384Z-debug.log
command=/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js rebuild ffi-napi@4.0.3 ref-napi@3.0.3 ref-napi@3.0.3
workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! application@3.1.5 package-lin: `tsc && electron-builder --linux`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the application@3.1.5 package-lin script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-11-24T08_15_40_421Z-debug.log
2. 解决过程
shellCopy
> export DEBUG=true; ./node_modules/.bin/build --linux --arm64
2. 注意到 gyp info spawn args 中的 node_modules 和 /root/.electron-gyp` 中gypi文件。
shellCopy
...
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/app/application/node_modules/_node-gyp@9.4.1@node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/app/application/node_modules/_ffi-napi@4.0.3@ffi-napi/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/app/application/node_modules/_node-gyp@9.4.1@node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/root/.electron-gyp/12.2.3/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/root/.electron-gyp/12.2.3',
gyp info spawn args '-Dnode_gyp_dir=/app/application/node_modules/_node-gyp@9.4.1@node-gyp',
gyp info spawn args '-Dnode_lib_file=/root/.electron-gyp/12.2.3/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/app/application/node_modules/_ffi-napi@4.0.3@ffi-napi',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
gyp ERR! configure error
...
2. cat /root/.electron-gyp/12.2.3/include/node/common.gypi 发现其中不存在openssl_fips 变量。
jsonCopy
{'variables':{'built_with_electron': 1}}
3. 手动添加openssl_fips 解决问题。
3. 解决方案
更改前
jsonCopy
{'variables':{'built_with_electron': 1}}
更改后
jsonCopy
{'variables':{'built_with_electron': 1, 'openssl_fips': ''}}