近期公司人事檢測公司人員電腦是否有違規檔案,原先都是人事通過人工看每臺電腦采集的資料,為了幫助他們快速檢測檔案我準備幫助他們做一個檔案分析工具,程式為單機版客戶端,因此我想到了用electron進行開發,
在使用electron-vue進行開發時比較順利,就跟平時使用vue開發專案一樣,但是在打包時遇到了問題,不知道什么原因,專案打包時候依賴與canvas的包,裝這個包遇到很多問題,
一、msvs_version was set from command line or npm config
gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2019
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - found in "C:\Program Files (x86)\Microsoft Visual Studio 14.0"
gyp ERR! find VS - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
本以為是我IDE的事,我使用的是VS Code 1.52.1,難道要換成最新版的Visual Studio?從網上查詢得知需要安裝windows-build-tools,需要注意的是,必須是以管理員身份來進行安裝,因此在打開cmd時要以管理員身份打開,
npm install --g --production windows-build-tools
二、Please restart this script from an administrative PowerShell
本以為會順利安裝windows-build-tools結果還是報錯了,
Starting installation...
Please restart this script from an administrative PowerShell!
The build tools cannot be installed without administrative rights.
To fix, right-click on PowerShell and run "as Administrator".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools@5.2.2 postinstall: `node ./dist/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools@5.2.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
問題在于我確定自己用的是管理員模式,為什么還是不行呢,查詢資料得之,需要全域安裝
reinstallnpm包然后再重新執行上邊命令,
npm install reinstall -g
npm install -g windows-build-tools
三、A dynamic link library (DLL) initialization routine failed
尷尬的事又發生了,我在裝打包環境時想再看看開發環境的系統,結果執行命令后報出這個錯誤,查詢了一下資料,Electron支持本機節點模塊,但是由于Electron使用的是與官方Node不同的V8版本,因此在構建本機模塊時必須手動指定Electron標頭的位置,
# On Windows if you have trouble, try:
.\node_modules\.bin\electron-rebuild.cmd
四、gyp ERR! stack Error: Can’t find Python executable “python”, you can set the PYTHON env variable.
編譯時報出這個錯誤,原來electron-vue打包還需要依賴Python,結果又安裝Python,
五、Cannot open include file: ‘cairo.h’: No such file or directory
打包時又報出來這樣的問題,經過網上查詢手動安裝node-canvas需要手動下載一些包到本地,具體參考連接文章即可,
- Installing node-gyp
- Installing GTK 2
- Installing libjpeg-turbo (optional, for JPEG support; node-canvas 2.0 and later)
- Installing node-canvas
六、不將程式打包為asar
在package.json的build中增加"asar": false
參考資料
electronjs
electron-vue
安裝node-canvas
A dynamic link library (DLL) initialization routine failed
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/240858.html
標籤:區塊鏈
