Fixing the node-sass binding through different docker architecture

Let’s say you can’t run NPM on your host machine for diverse reason and you want to run it in a docker container. Should prove to be super simple no? Wrong! (In the case you are using sass… I don’t know many people not using sass!)

Node sass bindings

So, the first problem that will arise is that if you find an image to run node properly with npm installed then you might have a different host architecture. For example, i run Ubuntu Linux x64 with NodeJS 10.

On my first dockerization try, i didn’t notice it but i had a NodeJS 8 image but that was fixed quickly looking at docker hub. I found a few but nothing worked out of the box until i got this one. Feel tree to use it if you want:


Next up, i needed to get node-sass running. The original problem i was getting was something like this:

ERROR in Missing binding /Users/warren/Sites/random-docs/my-cms/node_modules/node-sass/vendor/darwin-x64-11/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node 0.10.x

What this means is that you are trying to run node-sass with a binding that doesn’t match your host architecture, because yes, node-sass is just a wrapper to libsass.

If you run “npm install” off your system and your docker container is of a different architecture, then, your binding file will be the wrong one and you will never be able to start your dev server.

Fixing this

I came accross a github issue answer that found a parameter to pass on to the rebuild command.

npm uninstall node-sass && npm install node-sass --sass-binary-name=linux-x64-57

Now, don’t copy this and run this right off your console, you need to figure out which binding to use. In this example, the user is installing a very simple and common linux-x64 version of the binding but in my case i needed the musl version because i’m using the alpine container version.

Where do you get those binding names? Visit the node-sass project on github and search for the binary you need. If you don’t know which one it should be, just attempt to start your node server and it will probably yell at you the version it is looking for.

Errors you could get

So it ended up that using this approach wasn’t all perfect because i had various different permission errors i wasn’t aware. It doesn’t mean you will be having them but one thing you might want to do is simply trash your whole node_modules folder and try again


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.