node-sass: Docker ALPINE Linux throws node-sass missing binding error
- NPM version (
npm -v): 5.5.1 (but using yarn latest) - Node version (
node -v): 8.9.1 - Node Process (
node -p process.versions):
{ http_parser: '2.7.0',
node: '8.9.1',
v8: '6.1.534.47',
uv: '1.15.0',
zlib: '1.2.11',
ares: '1.10.1-DEV',
modules: '57',
nghttp2: '1.25.0',
openssl: '1.0.2m',
icu: '59.1',
unicode: '9.0',
cldr: '31.0.1',
tz: '2017b' }```
- Node Platform (`node -p process.platform`): linux
- Node architecture (`node -p process.arch`): x64
- node-sass version (`node -p "require('node-sass').info"`):
/app # node -p “require(‘node-sass’).info”
/app/node_modules/node-sass/lib/binding.js:15
throw new Error(errors.missingBinary());
^
Error: Missing binding /app/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 8.x
Found bindings for the following environments:
- OS X 64-bit with Node.js 8.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
at module.exports (/app/node_modules/node-sass/lib/binding.js:15:13)
at Object.<anonymous> (/app/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at [eval]:1:1
- npm node-sass versions (
npm ls node-sass):-- node-sass@4.6.0
So that’s the Dockerfile:
FROM node:8-alpine
EXPOSE 3000
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
RUN mkdir /app
WORKDIR /app
ADD . /app
RUN yarn --pure-lockfile
and the compose ‘dev’ file:
version: "3"
services:
client:
command: yarn dev
which runs:
"dev": "node build/dev-server.js",
(it’s a vue-cli script that uses webpack-dev-middleware)
and then… :
~/v/i/client (master|●6✚7) $ yarn docker:dev
yarn run v1.3.2
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
WARNING: Some services (client) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Recreating client_client_1 ...
Recreating client_client_1 ... done
Attaching to client_client_1
client_1 | yarn run v1.3.2
client_1 | $ node build/dev-server.js
client_1 | > Starting dev server...
client_1 | ERROR Failed to compile with 1 errors16:51:31
client_1 |
client_1 | error in ./src/components/Wrapper/wrapper.scss
client_1 |
client_1 | Module build failed: Error: Missing binding /app/node_modules/node-sass/vendor/linux_musl-x64-57/binding.node
client_1 | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 8.x
client_1 |
client_1 | Found bindings for the following environments:
client_1 | - OS X 64-bit with Node.js 8.x
client_1 |
client_1 | This usually happens because your environment has changed since running `npm install`.
client_1 | Run `npm rebuild node-sass --force` to build the binding for your current environment.
client_1 | at module.exports (/app/node_modules/node-sass/lib/binding.js:15:13)
client_1 | at Object.<anonymous> (/app/node_modules/node-sass/lib/index.js:14:35)```
How come node-sass sees OSX bindings? I thought it's an image/container...
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 28 (6 by maintainers)
Commits related to this issue
- Resolve node-sass binding issue References for the behavior: - https://github.com/sass/node-sass/issues/2162 - https://github.com/sass/node-sass/issues/1527 - https://github.com/sass/node-sass/issues... — committed to raft-tech/TANF-app by adamcaron 4 years ago
- Turns out I was using an old node:alpine image A lot can change in four months apparently, like no longer having a package called 'python' and forcing your users to actually specify which version the... — committed to bcspragu/Codenames by bcspragu 3 years ago
For the future adventurer: 1/ create a .dockerignore file with
2/ proceed as usual
3/ you will probably need to mount
node_modulesas a volume in yourdocker-compose.ymlfileI did this in my Dockerfile:
CMD [“npm”, “rebuild”, “node-sass”] CMD [“npm”, “start”]
I appreciate the swift reply but I’m afraid I did not understand the answer. (probably because the concept of docker is unclear still to me) I have the package json file and I’m running yarn install in the dockerfile therefore I expect yarn / npm to fetch the proper package for the O/S my docker is running on? (alpine in my case) What am I doing wrong there?
We supply Alpine binaries for newer version of node-sass.
Had similar issue while using official node docker image:
There is no node-sass binary for this node version, so, I had to downgrade to 10:
@xzyfer Hey I am not sure if this works for everybody but this one fixed our issue:
Or you can replace linux-x64-57 with the environment name you desire.
This is not an issue, it’s just how Node works. Native modules are built for a specific Node version, OS, and architecture combination i.e. Node 6 on 64-bit OSX.
Each release shows it’s support matrix i.e. https://github.com/sass/node-sass/releases/tag/v4.8.3
The issue here is that OP had installed node-sass OS X 64-bit with Node.js 8.x, then mounted
node_modulesinto a Linux docker container. Clearly that OS X binary could not work on Linux OS. The solution is to runnpm rebuild node-sassin the container to pull the correct binary.In production you would not be mounting files in to the container so
npm installis all you would need because it will fetch the correct binary for the container.You can’t mount native modules into different OSes. Run non rebuild node-sass on the container to get the right binding.
On 26 Nov. 2017 3:59 am, “George Katsanos” notifications@github.com wrote:
You should not use more than one CMD statement in your dockerfile Why can’t I use Docker CMD multiple times to run multiple services?
Because you’re mounting your node_modules folder running yarn isn doing nothing because all the packages look iike their installed. You should avoid mounting node_modules, instead mount the specific folders with your code.
On 26 Nov. 2017 9:35 am, “George Katsanos” notifications@github.com wrote:
I switch between builds on my local machine and docker containers in some projects. Node SASS is the only binary I have come across that seems to bork at the different operating systems. I basically have to run a rebuild every compile just in case I am in a different environment. Couldn’t Node SASS include all bindings and server up the correct one at runtime?
Hello, I had the same problem and I fixed it using
export SASS_BINARY_NAME=linux-x64-57but now I had other problem:I’m using the same config in my OSX and in Docker:
what about production setup?
You need to build your node_modules from your docker :
(Using docker compose ofc)
Wanted to report on my experience with this just now. My container was still getting the wrong binding, even when mounting the
node_modulesfolder as a named volume like so:Turns out that (at least on Windows), if you call your named volume
node_modules, it still seems to be causing some sort of confusion/collision with the folder. Changing the name of my volume fixed the issue.Alpine cannot use the Linux binary. It has it’s own binary. There’s is no need to do what you’re doing. Instead run npm rebuild node-sass
On Sat., 28 Jul. 2018, 2:41 am Juliane Albuquerque, < notifications@github.com> wrote:
It’s helpful for me. Webpack seem to find node-sass from the context folder, and if the os x node_modules is mounted as a volume, the error will happen. In this case, using a empty volume instead of the os x node_modules will be great. You shall write as:
Make the node_modules empty!~
For anyone attempting to do local development with docker-compose, I was able to get this working by adding an npm command
"docker:start": "npm rebuild node-sass && npm start"and then usingcommand: npm run docker:startin my compose file.node_modules is in .dockerignore but the whole working directory is being mounted in as a volume.
So I just came across this:
Error: Missing binding /app/node_modules/node-sass/vendor/linux_musl-x64-79/binding.node client_1 | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 13.x client_1 | client_1 | Found bindings for the following environments: client_1 | - Windows 64-bit with Node.js 10.x client_1 | client_1 | This usually happens because your environment has changed since running
npm install. client_1 | Runnpm rebuild node-sassto download the binding for your current environment.Sass version: “node-sass”: “^4.14.1”, node: 10.16.1
dockerFile:
dockerCompose:
What am I missing?
Tried several options above but nothing works.
For me, I have the problem with
yarn. After two hours research, I fixed this error bydocker exec -it myproject_frontend_1 bashand then runyarn add node-sass.Note: this is also relevant when building binaries with
zeit/pkg: since the Node.js binary is compiled against musl libc (apparently, or so node-sass thinks), you need to setSASS_BINARY_NAME. Otherwise, you’ll get something along the lines of:Hey all, sorry for re-opening this, but if you want to volume mount your host built node_modules AND have node-sass running, then you can instead build an image using your local OS and not use the pre-built node alpine image. Yes it is lengthy, but its only for development.
I use ubuntu (well ubuntu on WSL, hence the angular cli install that you’ll see later on), so I can just use the ubuntu image, install node, yarn and other things, then setup my app. Below is a real crude/just get it working Dockerfile to get my angular app (that using node sass) compiling and running:
Yes, real crude, but it works, so now I can volume mount my entire app to the WORKDIR and it will compile without any issues. Like I said in the comments, I’d suggest you create a separate image for the ‘OS’ part to save alot of time building it, but this really was for-the-win type concept.