electron项目打包编译遇到问题

发布时间 2023-04-20 16:01:20作者: 前端混子Ray

E:\ProjectSource-Code\87VR-Game-Electron> yarn package
yarn run v1.22.11
$ rimraf src/dist && yarn build && electron-builder build --publish never
$ concurrently "yarn build:main" "yarn build:renderer"
$ cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.main.prod.babel.js
$ cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.renderer.prod.babel.js
[0] Browserslist: caniuse-lite is outdated. Please run:
[0] npx browserslist@latest --update-db
[0]
[0] Why you should do it regularly:
[0] https://github.com/browserslist/browserslist#browsers-data-updating
[1] Browserslist: caniuse-lite is outdated. Please run:
[1] npx browserslist@latest --update-db
[1]
[1] Why you should do it regularly:
[1] https://github.com/browserslist/browserslist#browsers-data-updating
[1] (node:18152) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at E:\ProjectSource-Code\87VR-Game-Electron\node_modules\css-loader\node_modules\postcss\package.json.
[1] Update this package.json to use a subpath pattern like "./*".
[1] (Use `node --trace-deprecation ...` to show where the warning was created)
[0] [webpack-cli] Compilation finished
[0] asset ./src/main.prod.js 1.01 MiB [compared for emit] [minimized] (name: main) 1 related asset
[0] orphan modules 115 KiB [orphan] 30 modules
[0] runtime modules 1.03 KiB 5 modules
[0] modules by path ./node_modules/ 1.84 MiB 619 modules
[0] modules by path ./src/ 305 KiB
[0] modules by path ./src/node_modules/source-map/ 99.4 KiB 11 modules
[0] ./src/main.dev.ts + 20 modules 160 KiB [not cacheable] [built] [code generated]
[0] ./src/node_modules/regenerator-runtime/runtime.js 24.6 KiB [built] [code generated]
[0] ./src/node_modules/source-map-support/source-map-support.js 19.7 KiB [built] [code generated]
[0] ./src/node_modules/buffer-from/index.js 1.64 KiB [built] [code generated]
[0] 19 modules
[0]
[0] WARNING in ./node_modules/ws/lib/buffer-util.js 105:21-42
[0] Module not found: Error: Can't resolve 'bufferutil' in 'E:\ProjectSource-Code\87VR-Game-Electron\node_modules\ws\lib'
[0] @ ./node_modules/ws/lib/sender.js 8:38-62
[0] @ ./node_modules/ws/index.js 8:19-42
[0] @ ./node_modules/aria2/lib/JSONRPCClient.js 7:19-32
[0] @ ./node_modules/aria2/lib/Aria2.js 3:22-48
[0] @ ./node_modules/aria2/index.js 3:14-36
[0] @ ./src/file-manager/download/download_manage.ts 29:0-26 1027:31-36
[0] @ ./src/engine/Engine.ts 30:0-70 101:43-57
[0] @ ./src/main.dev.ts 39:0-37 138:28-34
[0]
[0] WARNING in ./node_modules/ws/lib/validation.js 4:22-47
[0] Module not found: Error: Can't resolve 'utf-8-validate' in 'E:\ProjectSource-Code\87VR-Game-Electron\node_modules\ws\lib'
[0] @ ./node_modules/ws/lib/sender.js 7:30-53
[0] @ ./node_modules/ws/index.js 8:19-42
[0] @ ./node_modules/aria2/lib/JSONRPCClient.js 7:19-32
[0] @ ./node_modules/aria2/lib/Aria2.js 3:22-48
[0] @ ./node_modules/aria2/index.js 3:14-36
[0] @ ./src/file-manager/download/download_manage.ts 29:0-26 1027:31-36
[0] @ ./src/engine/Engine.ts 30:0-70 101:43-57
[0] @ ./src/main.dev.ts 39:0-37 138:28-34
[0]
[0] webpack 5.5.1 compiled with 2 warnings in 7900 ms
[0] yarn build:main exited with code 0
[1] Browserslist: caniuse-lite is outdated. Please run:
[1] npx browserslist@latest --update-db
[1]
[1] Why you should do it regularly:
[1] https://github.com/browserslist/browserslist#browsers-data-updating
[1] [webpack-cli] Compilation finished
[1] asset renderer.prod.js 1.25 MiB [emitted] [minimized] (name: main) 1 related asset
[1] asset style.css 197 KiB [emitted] [minimized] (name: main)
[1] Entrypoint main 1.44 MiB = style.css 197 KiB renderer.prod.js 1.25 MiB
[1] 1026 modules
[1]
[1] WARNING in ./node_modules/systeminformation/lib/cpu.js 1183:20-53
[1] Module not found: Error: Can't resolve 'osx-temperature-sensor' in 'E:\ProjectSource-Code\87VR-Game-Electron\node_modules\systeminformation\lib'
[1] @ ./node_modules/systeminformation/lib/index.js 28:12-28
[1] @ ./src/AdbPage.tsx 35:0-35 325:2-26
[1] @ ./src/ViewManage.tsx 30:0-32 34:30-37
[1] @ ./src/index.tsx 7:0-39 8:26-37
[1]
[1] webpack 5.5.1 compiled with 1 warning in 12216 ms
[1] yarn build:renderer exited with code 0
• electron-builder version=23.6.0 os=10.0.19044
• loaded configuration file=package.json ("build" field)
• writing effective config file=release\builder-effective-config.yaml
• rebuilding native dependencies dependencies=usb-detection@4.14.2 platform=win32 arch=x64
• install prebuilt binary name=usb-detection version=4.14.2 platform=win32 arch=x64 napi=
• build native dependency from sources name=usb-detection
version=4.14.2
platform=win32
arch=x64
napi=
reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
error=prebuild-install info begin Prebuild-install version 7.1.1
prebuild-install warn install prebuilt binaries enforced with --force!
prebuild-install warn install prebuilt binaries may be out of date!
prebuild-install info looking for local prebuild @ prebuilds\usb-detection-v4.14.2-electron-v85-win32-x64.tar.gz
prebuild-install info looking for cached prebuild @ C:\Users\admin\AppData\Roaming\npm-cache\_prebuilds\3bd548-usb-detection-v4.14.2-electron-v85-win32-x64.tar.gz
prebuild-install http request GET https://github.com/MadLittleMods/node-usb-detection/releases/download/v4.14.2/usb-detection-v4.14.2-electron-v85-win32-x64.tar.gz
prebuild-install warn install read ECONNRESET

• rebuilding native dependency name=usb-detection version=4.14.2
⨯ cannot execute cause=exit status 1
$ prebuild-install || node-gyp rebuild

E:\ProjectSource-Code\87VR-Game-Electron\src\node_modules\usb-detection>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

errorOut=prebuild-install warn install connect ETIMEDOUT 20.205.243.166:443
gyp info it worked if it ends with ok
gyp info using node-gyp@9.1.0
gyp info using node@16.20.0 | win32 | x64
gyp info find Python using Python version 3.8.10 found at "C:\Users\admin\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe"
gyp info find VS using VS2019 (16.11.33529.622) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Users\admin\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\Users\\admin\\AppData\\Roaming\\nvm\\v16.20.0\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-I',
gyp info spawn args 'E:\\ProjectSource-Code\\87VR-Game-Electron\\src\\node_modules\\usb-detection\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\admin\\AppData\\Roaming\\nvm\\v16.20.0\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\admin\\.electron-gyp\\11.0.1\\include\\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\admin\\.electron-gyp\\11.0.1',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\admin\\AppData\\Roaming\\nvm\\v16.20.0\\node_modules\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\admin\\\\.electron-gyp\\\\11.0.1\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=E:\\ProjectSource-Code\\87VR-Game-Electron\\src\\node_modules\\usb-detection',
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 'E:\\ProjectSource-Code\\87VR-Game-Electron\\src\\node_modules\\usb-detection\\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
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\admin\AppData\Roaming\nvm\v16.20.0\node_modules\npm\node_modules\node-gyp\lib\configure.js:284:16)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Windows_NT 10.0.19044
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd E:\ProjectSource-Code\87VR-Game-Electron\src\node_modules\usb-detection
gyp ERR! node -v v16.20.0
gyp ERR! node-gyp -v v9.1.0
gyp ERR! not ok
error Command failed with exit code 1.

command='C:\Program Files\nodejs\node.exe' 'C:\Users\admin\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js' run install
workingDir=E:\ProjectSource-Code\87VR-Game-Electron\src\node_modules\usb-detection
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 

解决:最终更换node版本得到解决,切换一次没有解决多切换几次版本这种情况应该是node升级造成的;

1.node版本切换为18.16.0 问题依旧
2.node版本切换为14.17.2 问题依旧
3.node版本切换为16.20.0 问题依旧
4.node版本切换为14.21.3 问题解决