- node 编译 c++ 扩展的时候使用的编译工具
- depend on: python 2.7
开发一个 windows 小工具,工作 pc 是 ubuntu, 为了省事,选择用 electron,打算开发好了直接到 windows 上打包(ubuntu 上打 win 包还在研究中...)
因为 node-gyp 编译问题扯了一天半还没解决, 猜测 npm 安装 windows-build-tools 可能需要参数辅助或其它支持...
node-gyp 编译工具如何正确安装使用,在此作个记录
分 2 种情况:
Not exist Node
- 下载 .msi 安装包 https://nodejs.org
- 安装时(最好管理员运行)勾选:Automatically install the necessary tools ...
- 等待 安装程序 和 PowerShell 都执行完成
Already exist Node
包括 nvm 管理的 node
refer to:
- https://github.com/nodejs/nod...
- https://github.com/Microsoft/...
- https://github.com/nodejs/nod...
- https://nodejs.org/api/addons...
- https://www.jianshu.com/p/af7...
- https://blog.csdn.net/qq_3382...
setp
install Chocolatey (powershell or cmd)
// powershell (admin) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) // cmd (admin) @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"install windows-build-tools by Chocolatey
// install: Visual C++ Build Tools // powershell/cmd (admin) choco install visualcpp-build-tools - options: A如果未安装 python
- choco install python2
- npm i -g node-gyp
- npm config set msvs_version 2017 -g
node-gyp install
- powershell 需要修改执行策略, 执行:set-ExecutionPolicy RemoteSigned
node-gyp configure --msvs_version=2017
- 可忽略如下错误
gyp: binding.gyp not found (cwd: C:\Windows\system32) while trying to load binding.gyp gyp ERR! stack Error: `gyp` failed with exit code: 1[可选]resolve error: if not defined npm_config_node_gyp
windows 中 2 选 1 即可
- npm config set node_gyp "C:\Users\usr\AppData\Roaming\nvm\v12.14.1\node_modules\node-gyp\bin\node-gyp.js" -g
- set npm_config_node_gyp=node C:\Users\usr\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js -g
test: npm i -S
- mcrypt
- sqlite3
- node-sass
- kerberos
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用。你还可以使用@来通知其他用户。