Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Cache binaries (to use node-sass offline with npm 3.9.0) #1554

Closed
mriehema opened this issue May 18, 2016 · 10 comments
Closed

Cache binaries (to use node-sass offline with npm 3.9.0) #1554

mriehema opened this issue May 18, 2016 · 10 comments

Comments

@mriehema
Copy link

mriehema commented May 18, 2016

Hi, I just updated npm to 3.9.0 and using npm install --cache-min=Infinity which now works like an offline mode, but I got a problem with node-sass.

Our setup:

We have a huge java/maven based workspace with some frontend stuff. We use the frontend-maven-plugin to call node/npm and grunt. This worksapce is build on Linux, MacOSX and Windows. For the frontend we use grunt-sass, which based on node-sass. Every mvn clean install will delete the node_modules folder and redownload all dependencies needed. This is important for our CI, because its the same way our customer are using the workspace. This works nice as long as you are online.

Problem:

Some of our consultants and customers want/need to work offline. We couldn't support it yet, because of the problems with the npm cache. Since release 3.9.0 fixed this problem, it works offline with all our modules (if you at least build it once online = cached), but not with node-sass.

Possible Solution:

  1. Put the binaries into the bundle: not an option, like you said in Why does node-sass downloads\builds the binding on each npm install?  #654 (comment) to save bandwidth.
  2. Configure SASS_BINARY_PATH: not an option for us, because we have to put the binaries into our source workspace and need to configure it. So we have to maintain the binaries for all systems and versions... Sounds like an antipattern.
  3. Download and keep the binaries in a temp folder. Check this location, before redownloading them. This is how phantomjs is doing it with their binaries. My favorite solution. This saves bandwidth and time AND would work offline too!

Here is an extract of the npm log to show how phantomjs/node-sass are doing it:

phantomJS

[INFO] > [email protected] install C:\workspace\basic-theme\node_modules\phantomjs-prebuilt
[INFO] > node install.js
[INFO]
[INFO] Considering PhantomJS found at C:\Program Files (x86)\phantomjs\bin\phantomjs.EXE
[INFO] Found PhantomJS at C:\Program Files (x86)\phantomjs\bin\phantomjs.EXE ...verifying
[INFO] PhantomJS detected, but wrong version 2.0.0 @ C:\Program Files (x86)\phantomjs\bin\phantomjs.EXE.
[INFO] Download already available at C:\Users\mriehema\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
[INFO] Verified checksum of previously downloaded file
[INFO] Extracting zip contents
[INFO] Removing C:\workspace\basic-theme\node_modules\phantomjs-prebuilt\lib\phantom
[INFO] Copying extracted folder C:\Users\mriehema\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip-extract-1463578294927\phantomjs-2.1.1-windows -> C:\workspace\basic-theme\node_modules\phantomjs-prebuilt\lib\phantom
[INFO] Writing location.js file
[INFO] Done. Phantomjs binary available at C:\workspace\basic-theme\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe

node-sass:

[INFO] > [email protected] install C:\workspace\basic-theme\node_modules\node-sass

[INFO] > node scripts/install.js
[INFO]
[ERROR] Cannot download "https://github.com/sass/node-sass/releases/download/v3.7.0/win32-x64-46_binding.node":
[ERROR]
[ERROR] getaddrinfo ENOENT github.com:443
[ERROR]
[ERROR] Hint: If github.com is not accessible in your location
[ERROR]       try setting a proxy via HTTP_PROXY, e.g.
[ERROR]
[ERROR]       export HTTP_PROXY=http://example.com:1234
[ERROR]
[ERROR] or configure npm proxy via
[ERROR]
[ERROR]       npm config set proxy http://example.com:8080

So it would be a very cool feature, if node-sass could support cached/temp binaries to save bandwidth and to support an offline mode! Thx.

@xzyfer
Copy link
Contributor

xzyfer commented May 18, 2016

We have multiple ways to support offline binaries documented in the readme - https://github.com/sass/node-sass#binary-configuration-parameters

@xzyfer xzyfer closed this as completed May 18, 2016
@mriehema
Copy link
Author

mriehema commented May 18, 2016

As fast as you closed this ticket, I think you didn't even read it. :(
Its not only about support offline binaries, it's about caching and speed up installation.

@mriehema mriehema changed the title Use node-sass offline with npm 3.9.0 Cache binaries (to use node-sass offline with npm 3.9.0) May 18, 2016
@xzyfer
Copy link
Contributor

xzyfer commented May 18, 2016

I was able to close this quickly because it has come up multiple times.

I suggest setting up an internal mirror of the binaries so you have all the versions available locally within your firewall. It's the most robust solution and is how most of our enterprise users work around your issue.

I understand what you're asking for but it would complicate what is already a complicated install process.

@mriehema
Copy link
Author

Please take at least a small look at the install script of phantomJS. That doesn't look to complicated to me to be integrated into your install script.

@phofmann
Copy link

Hi,
no, a internal mirror is not an option. I am travelling a lot. Therefore I am not able to connect to an internal mirror installed within my company. I need to be able to run completely offline as mriehema described above.

@xzyfer
Copy link
Contributor

xzyfer commented May 18, 2016

I'm sorry that's not an option for you. There are two options, setup a local http mirror, or a local filesystem mirror.

The later is exactly the same as the solution suggested except that it's manual.

@dzrw
Copy link

dzrw commented Nov 23, 2017

Do you think you could document how to setup this cache for CircleCI/TravisCI? I know those aren't your focus, but spending 2 minutes per build building node-sass is pretty gruesome.

You'd be doing the world a favor in terms of reducing the amount of CO2 produced generating the electricity to build node-sass thousands of times daily on CI platforms. Go green! Make node-sass eco-friendly! Help the planet!

@xzyfer
Copy link
Contributor

xzyfer commented Nov 23, 2017 via email

@michallepicki
Copy link

michallepicki commented Apr 26, 2018

@xzyfer I can never pull a prebuilt binary. Currently I'm getting:

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.8.3/linux-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.8.3/linux-x64-64_binding.node":

edit:
If anyone has the same problem, this is probably because node 10 is not supported for node-sass v4.8.3 . Either downgrade node or update node-sass to 4.9.0.

I wish the error message suggested checking version compatibility!!

@xzyfer
Copy link
Contributor

xzyfer commented Apr 26, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants