search

Home  >  Q&A  >  body text

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

问题

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

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

天蓬老师天蓬老师2785 days ago662

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-17 15:34:43

    Can you give me more details, for example, what kind of bag is it packed in?
    This is my plan, you can try it:

    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 is the version number of electron

    Then please note that node-sass downloads the compiled binary file by default, so you need to re-specify it. My method is as follows, which is not the only one:

    process.env.SASS_BINARY_PATH = path.join(__dirname, './node_modules/node-sass/build/Release/binding.node');

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:34:43

    One thing you need to know is to switch the node version directly. The modules installed by node_modules are 无法使用.
    The node_model installed in node4.x cannot be used normally if you switch to version 6.x and needs to be 删掉restartednpm install.
    So I suggest you upgrade your local machine to 6.x, install the module and then package the application (nvm can help you manage the installation switching of multiple node versions).

    reply
    0
  • Cancelreply