您的位置:首页技术文章
文章详情页

node.js - electron使用原生node模块

【字号: 日期:2024-07-29 11:58:40浏览:67作者:猪猪

问题描述

问题

本地node是4.X,electron的是6.X,导致npm安装的模块不能在electron上使用

尝试使用electron-rebuild解决,但一直报错

node.js - electron使用原生node模块

问题解答

回答1:

能说得详细点么,比如说装的是什么包?这是我的方案,你可以试试:

node-gyp --target=1.3.5 --runtime=electron --fallback-to-build --directory ./node_modules/node-sass --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist configure

node-gyp --target=1.3.5 --runtime=electron --fallback-to-build --directory ./node_modules/node-sass --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist rebuild

target 是electron的版本号

然后注意node-sass 默认下载已编译好的二进制文件,所以需要重新指定,我的办法如下,不唯一:

process.env.SASS_BINARY_PATH = path.join(__dirname, ’./node_modules/node-sass/build/Release/binding.node’);回答2:

有一点你需要知道,直接切换node版本,node_modules安装的模块是无法使用的。node4.x装的node_model,切换6.x版本无法正常使用,需要删掉重新npm install。所以我建议你把本地升级到6.x,安装模块再打包应用程序(nvm可以帮你管理多个node版本的安装切换)。

相关文章: