node.js - electron使用原生node模块
问题描述
问题本地node是4.X,electron的是6.X,导致npm安装的模块不能在electron上使用
尝试使用electron-rebuild解决,但一直报错
问题解答
回答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版本的安装切换)。
相关文章:
1. python相关问题求解决,有偿2. javascript - input输入框触发change事件后,外部元素会被选中3. python - 用__call__ 实现装饰器功能4. javascript - 把字符串日期转换成一般时间格式后,发现小于10的数字不会自动添加0在前面,如下5. javascript - 在sublime中如何给.vue文件注释?6. javascript - js判断一个数组是否重复7. python - 请问用cxfreeze打包的可执行程序能反编译出源码么?8. javascript - vue2.0中router.repalce跟router.push有什么区别,二者的应用场景是会有怎样的区别?9. javascript - 这种上传图片预览怎么做?10. javascript - prismplayer播放器全屏问题