electron 使用原生node 模块
来源:互联网 发布:淘宝定金尾款几天内 编辑:程序博客网 时间:2024/05/06 08:34
electron 使用原生node 模块
The native Node modules are supported by Electron, but since Electron is verylikely to use a different V8 version from the Node binary installed in yoursystem, you have to manually specify the location of Electron's headers whenbuilding native modules.
原生node模块都能用于electron ,但是因为使用了不同的v8内核的原因,需要重新编译才能使用
原生模块,主要指那些c/c++的写的扩展,例如sqllite,ffi这些模块。为了调用第三方DLL,addon太复杂,ffi 不错。
前置条件:
需要本地安装vs2015或Visual C++ Build Tools, python2.7.11
cnpm install node-gyp -g
好了,必要条件满足了,就可看下面:
官网提供了三种方式:
1、Using npm
# Electron's version.export npm_config_target=1.6.2# The architecture of Electron, can be ia32 or x64.export npm_config_arch=x64export npm_config_target_arch=x64# Download headers for Electron.export npm_config_disturl=https://atom.io/download/electron# Tell node-pre-gyp that we are building for Electron.export npm_config_runtime=electron# Tell node-pre-gyp to build module from source code.export npm_config_build_from_source=true# Install all dependencies, and store cache to ~/.electron-gyp.HOME=~/.electron-gyp npm installwindows下export 换成 set
这种方式正常情况下是没问题的,苦逼的中国IT 人 遇到最大的问题是
https://atom.io/download/electron 国内访问经常超时,导致下载不成功。万能的TB 出现了, set npm_config_disturl=https://npm.taobao.org/mirrors/atom-shell换成这个还是会有些报错,主要是少几个其他无关紧要的文件,这个时候只能看出错提示哪里报错 注释哪里。2、Installing modules and rebuilding for Electron 安装模块并重新编译为指定版本使用npm install --save-dev electron-rebuild遇到的问题跟上面一样,下载必要的文件超时,因为默认是连接到s3.amazonaws.com# On Windows if you have trouble, try:.\node_modules\.bin\electron-rebuild.cmd
慢到吐血,悲了个催的。处理方法同上,哪里报错注释哪里。
这种方式因为不好定义 下载源,我没有测试。
3、Manually building for Electron 手动编译原生模块为指定的electron 版本
cnpm install ffi --save //先安装模块,会自动安装依赖 ref
进入模块对应的目录分别编译
cd node_modules/fficd node_modules/ref正常来说应该用这个命令
node-gyp rebuild --target=1.6.2 --arch=ia32 --target_arch=ia32 --dist-url=https://atom.io/download/electron --msvs_version=2015
网络的原因,你懂的 ,换成这个
node-gyp rebuild --target=1.6.2 --arch=ia32 --target_arch=ia32 --dist-url=https://npm.taobao.org/mirrors/atom-shell --msvs_version=2015
好吧,跟方案一样,少文件了,从出错的位置 手动定位到文件install.js 改改改
/*if (res.statusCode !== 200) {
done(new Error(res.statusCode + ' status code downloading checksum'))
return
}*/
if (res.statusCode !== 200) {
//done(new Error(res.statusCode + ' status code downloading 64-bit ' + release.name + '.lib'))
return
}
大概有3、4个地方,改改就能正常安装了,泪流满面啊。。。
后记:这个问题纠缠了我2、3天,叫天天天不应,stackoverflow也没有这种问题的答案
网络问题是阻碍人类进步的 绊脚石。。。何时才能国际接轨啊???
node.js很多模块都是开源的,不行就HACK 下。
Node.js 安装模块遇到 MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,
1) 安装 .NET Framework 2.0 SDK;2) 安装 Microsoft Visual Studio 2005;或 3) 如果将该组件安装到了其他位置,请将其位置添加到系统路径中。
gyp ERR! stack Error
一般是没有指定 vs 版本 ,加上参数即可 --msvs_version=2015 以下是64位系统中的编译命令行
node-gyp rebuild --target=1.6.5 --arch=x64 --dist-url=https://npm.taobao.org/mirrors/atom-shell --msvs_version=2015
感谢 http://www.cnblogs.com/conorpai/p/6407010.html 给了我方向。
0 0
- electron 使用原生node 模块
- Node.js & Electron的扩展模块
- 在 Node.js 中使用原生的 ES 模块
- Electron使用NodeJS扩展模块调用DLL
- node-bindings无法在Electron中使用的解决办法
- 使用electron构建跨平台Node.js桌面应用
- 使用electron构建跨平台Node.js桌面应用
- 使用electron构建跨平台Node.js桌面应用
- 使用electron构建跨平台Node.js桌面应用
- node-canvas模块使用
- Electron 调用本地模块
- react native使用原生模块
- react native使用原生模块
- 安装Node.js和Electron
- node.js使用forever模块
- Node.js 使用async模块
- node(使用events模块)
- nodejs模块 node-schedule 使用
- 中美视觉的VI设计程序
- ASP.NET EXCEL导入
- 初识Sass与Koala工具的使用
- [leetcode 513. Find Bottom Left Tree Value]medium | week6
- 通信协议之SPI
- electron 使用原生node 模块
- PCA主成分分析(降维)
- Androoid WebView加载html调用手机拍照和相册
- 警惕颈纹袭击 倾城汇告诉你颈部如何护理
- Elasticsearch并发控制
- Robotics Library (C++机器人库)(翻译+精简+学习)(常见的问题)
- 递推递归练习I蟠桃记
- mysql 经纬度坐标定位 算距离
- Gym