Node-sass: Specify node-sass binary location via file path and not HTTP

Created on 19 Jul 2018  Â·  13Comments  Â·  Source: sass/node-sass

Hi,

I'm just wondering why the only option to fetch the node sass binaries is through HTTP with the option to give an alternative HTTP url for them. How come I just can't download the ones for my project and put something in .npmrc to specify where they are on the file system?

I thought sass_binary_path or sass_binary_dir would solve this but it seems those two options just allow you to determine where the binaries will store after their download.

Thanks,

Andre

Most helpful comment

This took me a while to get right as well. It's not stated in the documentation, but as said above SASS_BINARY_DIR expects a specific directory structure.

For example, with node-sass 4.10.0 you'd download the binary:
v4.10.0/linux-x64-57_binding.node

Rename the file to binding.node and place it in a new folder linux-x64-57.

If using /opt/lib the full binary path would be /opt/lib/node-sass/linux-x64-57/binding.node

Used with the environment variable:
SASS_BINARY_DIR=/opt/lib/node-sass

All 13 comments

SASS_BINARY_DIR should do what you're after. Make sure it's an absolute path, and that the binary name is unchanged.

Try using an environment variable. I don't believe we supply .npmrc

On Fri., 20 Jul. 2018, 9:44 am Andre, notifications@github.com wrote:

Interesting. I did try that and I get the following error:

[image: node-sass-binary-issue]
https://user-images.githubusercontent.com/2465008/42975678-150d7448-8b83-11e8-8668-5f5ce262b10a.png

My npmrc looks like this:

[image: npmrc]
https://user-images.githubusercontent.com/2465008/42975744-8ba89542-8b83-11e8-9c32-b50d3d4d52e3.png

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/sass/node-sass/issues/2455#issuecomment-406446521,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjZWLitchTN6BdZzubFUwfTe-kcNSfXks5uIRmTgaJpZM4VWzs0
.

Can you supply the value you set and an annonimized gist for the log. It's hard do go off screenshots

It also seems like the value you might want to set is SASS_BINARY_PATH not DIR

I've tried path too but it always wants to download for the first time.

Maybe, I've never really used those variables. For my offline machines I actually just stuff the binary in the NPM cache on any offline machines so the install just picks it up after I do that once for the Node/Node-Sass combo.
I'm taking a look at the docs now though

SASS_BINARY_DIR is exactly that, a directory. The binary name will be appended to the resolved directly.

If you want alter the binary name for some reason use SASS_BINARY_NAME (don't do this).

I have using these options all week so I'm certain they work :)

SASS_BINARY_PATH is the absolute path of the binary file i.e.

SASS_BINARY_PATH=/tmp/test/darwin-x64-57_binding.node npm install node-sass

SASS_BINARY_DIRECTORY is the absolute path to alternate location for the binaries instead to node-sass/vendor

SASS_BINARY_DIRECTORY=/tmp/test npm install node-sass

The binary path is a directory that is expected to mirror the layout of vendor i.e.

$ ls test
darwin-x64-57
$ ls test/darwin-x64-57
binding.node

I don't understand why they just can't be part of the project unless it's related to versioning and file size?

Because no one wants to install 100s of mbs of binaries - https://github.com/sass/node-sass/releases/tag/v4.9.2

If you can do better we welcome your PR.

Please read my previous comment. It's clear from your screen shot above you've setting SASS_BINARY_DIR incorrectly.

If you're using SASS_BINARY_DIR it's expected that inside that directly there is win32-x64-57/binding.node. The SASS_BINARY_DIR must not include the win32-x64-57/binding.node.

Alternatively use SASS_BINARY_PATH to the full path to the .node file.

I've struggeled with this too for too long until I found a solution using the "cache_dir"-config:
In project_root/.npmrc:
sass_binary_cache=../../myNpmCacheDir/node-sass/vendor
in project_root/myNpmCacheDir/node-sass/vendor I put the cached binary(ies) in the following structure:
node-sass/4.10.0/win32-x64-64_binding.node
Complete path:
project_root/myNpmCacheDir/node-sass/vendor/node-sass/4.10.0/win32-x64-64_binding.node which will only then be used by the package.json-install-script

I wasn't very well documented so it's probably better and easier to write example configs instead of trying to explain the structure in docs.

This took me a while to get right as well. It's not stated in the documentation, but as said above SASS_BINARY_DIR expects a specific directory structure.

For example, with node-sass 4.10.0 you'd download the binary:
v4.10.0/linux-x64-57_binding.node

Rename the file to binding.node and place it in a new folder linux-x64-57.

If using /opt/lib the full binary path would be /opt/lib/node-sass/linux-x64-57/binding.node

Used with the environment variable:
SASS_BINARY_DIR=/opt/lib/node-sass

For those having the same issue and looking for the official documentation of these variables, see https://github.com/sass/node-sass/tree/master#binary-configuration-parameters

Variable name | .npmrc parameter | Process argument | Value
-----------------|------------------|--------------------|------
SASS_BINARY_NAME | sass_binary_name | --sass-binary-name | path
SASS_BINARY_SITE | sass_binary_site | --sass-binary-site | URL
SASS_BINARY_PATH | sass_binary_path | --sass-binary-path | path
SASS_BINARY_DIR | sass_binary_dir | --sass-binary-dir | path

(copied table as links tend to break after some time)

Was this page helpful?
0 / 5 - 0 ratings