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

Why does node-sass downloads\builds the binding on each npm install? #654

Closed
yonidor opened this issue Feb 9, 2015 · 13 comments
Closed

Comments

@yonidor
Copy link

yonidor commented Feb 9, 2015

Hi,

I have a problem where we just integrated node-sass, on our CI machines, each build calls npm install which redownloads the binding file. I saw the option to suppress the download and let python build the binding for me, but my question is why can't the binding be downloaded as part of the package?

@am11
Copy link
Contributor

am11 commented Feb 9, 2015

Hi,

Q. Why does node-sass downloads\builds the binding on each npm install?

Preciseness & Bandwidth-friendliness:

Each platform (Mac, Linux etc.) has its own binary for each architecture (x86-64, x86-32), so instead of downloading everything on your system, this way we detect your system in our post install script and download the matching binary from a separate repo: https://github.com/sass/node-sass-binaries.

Q. Is this the best way?

npm package is a distilled form, we cannot modify or make decisions at install time to cherry pick constituents of package. We used to bundle binaries in npm sometime ago. We realised this approach is better due to the aforementioned reason.

Q. What is the other option?

Download all binaries, and delete them except the one which is suitable for your system. This approach is non-bandwidth-friendly.

Related: #655.

@yonidor
Copy link
Author

yonidor commented Feb 9, 2015

First of all, great answer.

The optimal solution i see for me is to have a local copy of binding.node (in the version i need) and copy it to the appropriate place right after 'npm install' is ran.
Can i achieve that by using SKIP_SASS_BINARY_DOWNLOAD_FOR_CI and SKIP_NODE_SASS_TESTS env vars?

@am11
Copy link
Contributor

am11 commented Feb 9, 2015

Implicitly yes. SKIP_SASS_BINARY_DOWNLOAD_FOR_CI = true will skip the download and try to manually build the binary. Then SKIP_NODE_SASS_TESTS = true will skip building the binary. You can then manually download the binary in /vendor directory.

@yonidor
Copy link
Author

yonidor commented Feb 9, 2015

Cool, many thanks!

@yonidor yonidor closed this as completed Feb 9, 2015
@janusch
Copy link

janusch commented Apr 7, 2016

@am11 Hey,
this issue touches exactly my problem. I have put the binaries into the node-sass directory in vendor/. Now the postinstall fails because of node-gyp not being able to rebuild. How can I skip the node-gyp re-build and just use the binaries in vendor/ ?

@am11
Copy link
Contributor

am11 commented Apr 7, 2016

Hej @janusch,

Run:

# in CLI
node -p "[process.platform, '-', process.arch, '-', process.versions.modules].join('')"

and note its output. If you have a subdirectory with that name under vendor/, then postinstall will skip rebuilding the binary.

@janusch
Copy link

janusch commented Apr 11, 2016

@am11 thank you for getting back to me!

Here is the output from from the command above:

test_i$ node -p "[process.platform, '-', process.arch, '-', process.versions.modules].join('')"
linux-x64-46

I think I realized what went wrong, the vendor dir is not included when I npm publish . Do you know how I can add the binaries when publishing to local npm?

@janusch
Copy link

janusch commented Apr 11, 2016

@am11 Hey,
I just tried to publish node-sass with binaies after git cloneing the node-sass repo and git checkout of the last stable release. Sadly it still does not include vendor/ dir. I do not have experience with publishing node packages, so it is probably a stupid mistake. If you know what I am doing wrong, please let me know.

Would it make more sense to go for plan B and install a libsass linux package instead and node-sass can skip installing any binaries?

Thank you again for taking the time to walk me through this!

@xzyfer
Copy link
Contributor

xzyfer commented Apr 11, 2016

I believe this is fixed on master. We'll be releasing 3.5.0 stable in a
couple days. Just waiting on LibSass to finish up 3.3.5.
On 11 Apr 2016 8:58 PM, "Janusch" [email protected] wrote:

@am11 https://github.com/am11 Hey,
I just tried to publish node-sass with binaies after git cloneing the
node-sass repo and git checkout of the last stable release. Sadly it
still does not include vendor/ dir. I do not have experience with
publishing node packages, so it is probably a stupid mistake. If you know
what I am doing wrong, please let me know.

Would it make more sense to go for plan B and install a libsass linux
package instead and node-sass can skip installing any binaries?

Thank you again for taking the time to walk me through this!


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#654 (comment)

@janusch
Copy link

janusch commented Apr 11, 2016

@xzyfer sorry. I used this issue for my own problem with not being able to download binaries due to no internet connection. I think i just figured it out. Just had to add the vendor dir with the binaries downloeaded for my system into package.jsons files array

"files": [
    "bin",
    "binding.gyp",
    "lib",
    "scripts",
    "vendor",
    "src"
  ]

Sorry again for putting this into an issue that was meant for something else, I had lost track.
Keep up the great work!

@janusch
Copy link

janusch commented Apr 11, 2016

Hey @am11 @xzyfer ,
Sorry to bother you again. I thought I had figured it out. But now on testing without internet. I still get errors in the postinstall process.

I had to pull in the libsass git submodule. Now it builds but I am not sure what should go into the patched node-sass package that is fully standalone.

Could you point me to a guide that helps with builiding a standalone node-sass package.
E.g. do I need to set those env. variables? SASS_BINARY_PATH and LIBSASS_EXT. I am currently setting SKIP_SASS_BINARY_DOWNLOAD_FOR_CI=true that helped a bit when there is not connection.

Could you please give me an example of the SASS_BINARY_PATH for when the binaries are within the node_modules/node-sass/vendor dir?

How can building libsass be skipped, or do I need to add the git submodule to the package?

Would be delighted if we get this to work!

edit. Here is the npm-debug info that could be relevant:

Error: node-sass@10.4.2 postinstall: `node scripts/build.js`
Exit status 1
    at EventEmitter.<anonymous> (/usr/share/npm/lib/utils/lifecycle.js:232:16)
    at EventEmitter.emit (events.js:98:17)
    at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:24:14)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:766:16)
    at Process.ChildProcess._handle.onexit (child_process.js:833:5)

@am11
Copy link
Contributor

am11 commented Apr 11, 2016

Are you trying to install node-sass offline with git source? If so, you would need to have the repo cloned recursively to pull the libsass submodule: git clone https://github.com/sass/node-sass --recursive; unfortunately, github's zip does not include the submodules. Alternatively, you can download libsass zip in addition to node-sass, extract node-sass in ./node-sass, extract libsass in ./node-sass/src/libsass and run: cd ./node-sass && npm install.

@janusch
Copy link

janusch commented Apr 12, 2016

@am11 great, this fixed it!
Thank you very much for pointing this out.
Finally I have a working package of node-sass with binaries, thank you!

jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants