Search code examples
node.jswindowsnw.jsnode-sassnwjs

How to include node-sass in nwjs (on windows)


I'm working on a multi-platform project in NW.js (node-webkit) and it has to use node-sass. The problem is that I can't seem to find any way to include it without an error on windows (x64).

Here's what I've tried:

  1. Require as is
    Error: A dynamic link library (DLL) initialization routine failed.
  2. Build with node-sass' built in script and then require
    Error: A dynamic link library (DLL) initialization routine failed.
  3. Build with node-gyp
    Error: A dynamic link library (DLL) initialization routine failed.
  4. Build with nw-gyp (configure command fails)
    Error: name 'component' is not defined while evaluating condition 'OS=="win" and component=="shared_library" in binding.gyp while trying to load binding.gyp

I've tested this on Windows 10 (x64), node v6.5.0, NW.js v0.16.1 and v0.17.0, node-sass (latest).

Thanks for your help!


Solution

  • What I ended up doing is:

    I created a wrapper around node-sass that calls node-sass as a child process (through the cli).

    const { exec } = require('child_process');
    module.exports = function (options, cb) {
        // turn the options to node-sass cli args
        // something like this...
        exec(`node-sass ${agrs}`, execOptions, cb);
    }
    

    Works like a charm! ;)