node.js - electron使用原生node模塊
問題描述
問題本地node是4.X,electron的是6.X,導(dǎo)致npm安裝的模塊不能在electron上使用
嘗試使用electron-rebuild解決,但一直報錯
問題解答
回答1:能說得詳細(xì)點(diǎn)么,比如說裝的是什么包?這是我的方案,你可以試試:
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 默認(rèn)下載已編譯好的二進(jìn)制文件,所以需要重新指定,我的辦法如下,不唯一:
process.env.SASS_BINARY_PATH = path.join(__dirname, ’./node_modules/node-sass/build/Release/binding.node’);回答2:
有一點(diǎn)你需要知道,直接切換node版本,node_modules安裝的模塊是無法使用的。node4.x裝的node_model,切換6.x版本無法正常使用,需要刪掉重新npm install。所以我建議你把本地升級到6.x,安裝模塊再打包應(yīng)用程序(nvm可以幫你管理多個node版本的安裝切換)。
相關(guān)文章:
1. android - webview 自定義加載進(jìn)度條2. 為什么我ping不通我的docker容器呢???3. javascript - 微信小程序限制加載個數(shù)4. linux - openSUSE 上,如何使用 QQ?5. mysql - 怎么讓 SELECT 1+null 等于 16. python 怎樣用pickle保存類的實(shí)例?7. 并發(fā)模型 - python將進(jìn)程池放在裝飾器里為什么不生效也沒報錯8. 大家好,請問在python腳本中怎么用virtualenv激活指定的環(huán)境?9. linux - 升級到Python3.6后GDB無法正常運(yùn)行?10. Python中, 仿照經(jīng)典代碼實(shí)現(xiàn)單例, 卻出現(xiàn)了不是單例的的狀態(tài), 代碼哪里出錯了 ?
