Cross Platform Sass compilation with node-sass (libsass)


I just started to experiment with electron and would like to build a simple app which compiles Sass using node-sass. When I develop (Linux Xubuntu) this is no problem. The app works great but when I run my app on Windows (after packaging) it gives me the infamous error:
Error: `libsass` bindings not found. Try reinstalling `node-sass`

I tried to solve this by downloading the precompiled binary from node-sass-binaries but than it gives me the following error:
A dynamic link library (DLL) initialization routine failed.
This has been discussed here. But to me It is not clear how to solve this.

The question is simple:
Is there a way to have node-sass working cross platform in an electron app?


For the time being I don’t see a cross platform way of doing this. For now I will look into compiling manually or automated from each platform. See discussions here and here

If anyone has a better idea on how to solve this cross platform please post a reply.


Alright, here’s what I’ve got. It’s not the best way to do it, but I was able to get past the DLL error without a problem.

  1. I installed Node v5.1.1 using nvm and reinstalled electron-prebuilt and electron-rebuild globally. I don’t actually know if you need to do this, but I wanted to be running on the same version of Node as Electron.

  2. I followed the instructions listed here, including running the build script just to make sure I didn’t have any issues doing that. It’s worth noting that you cannot just run npm install node-sass and have it work; you have to follow those instructions.

  3. In scripts/build.js, I added the following arguments to the path.join() on line 133:

     '--target=0.36.10', '--arch=x64', '--dist-url='

    so the line now reads:

     var args = [require.resolve(path.join('node-gyp', 'bin', 'node-gyp.js')), 'rebuild', '--verbose', '--target=0.36.10', '--arch=x64', '--dist-url='].concat(
  4. After running node scripts/build -f from the node-sass directory, I copied the resulting binding.node file from vendor/win32-x64-47 to the node-sass directory in my project’s node_modules, replacing the previous build.

Once I did that, I was able to run Electron without any DLL issues. I’m dealing with other unrelated bugs right now that are crashing my Electron app, so I haven’t tested to see whether it works or not yet, but so far it’s something.

Right now, you’d probably have to create a build for each platform you’re planning on deploying to, or include the modified node-sass source and a compiler that node-gyp can work with.

EDIT: It might not be fully working as expected. My project (so far) uses the Harp web server, which has node-sass as a dependency. When running Electron with Foundation 6 for Sites, I get a Sass compiler error saying media query expression must begin with ')', but if I go to the frontend directory and run harp server from the CLI it works without a problem.

I’m going to experiment some more to figure out what’s going on and to see if I can fix it. electron-rebuild seems to be broken on my end for whatever reason…


Thank you for replying. Great to hear to got somewhere with this.

I kind of gave up on it for the moment but this gives me some hope :slight_smile: I have followed these instructions but that led me to another error but I forgot which one. I think that pretty much comes down to the same what you did: rebuilding libsass with the right version of node and electron headers. I did use nvm as well to change to the right version of node before rebuilding but without any success. But I will try it like you suggested. Maybe it will work :smiley:


I don’t know what is different in the approach you posted and what the I followed but this is working! Awesome.

I would still like to figure out how to make this work cross platform. But for that we would need a similar solution to how node-sass solved their other builds.

Would you consider helping out building electron support right into node? Your help would be greatly appreciated.
Check the discussion here.

EDIT: Tried this without step 1 and still works.