Node-sass and Node-gyp Errors

July 19th, 2022

Chipper CI is continuous integration, just for Laravel. Give it a try - free!

Fixing Node-Gyp Errors:

One of the more annoying issues of developing on a full stack framework are NodeJS build errors. I just want my static assets! It's not even something important that's broken!

A common issue I've seen when building a project in a CI environment is related to using Node-Sass.

Node-Sass seems to use Node-gyp to compile … something … and fails!

The error is something like this:

gyp ERR! build error
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

It turns out that Node-gyp is a package used for compiling stuff for NodeJS add-ons. Node-Sass happens to use it to compile native binaries that the project needs to build CSS.

Here's the important part:

The version of Node-Sass used is only compatible with certain versions of Node.

The Node-Sass GitHub page has an extremely important table showing version compatibilities:

node-sass compatibility

What To Do

So, if you see Gyp build errors related to the node-sass package, you need to ensure your version of Node matches the version of Node-Sass being installed.

Within a CI environment, the fix is usually to make sure you are using the correct NodeJS version (rather than changing the version of Node-Sass).

In Chipper CI, this means setting the Node version in the environment section of the .chipperci.yml file (Yaml docs here):

version: 1

# Important part here
  php: 8.1
  node: 14 # Node 14 for Node-sass 4.14+,  but less than 5.0


  - name: Setup
    cmd: echo "setting up!"

Make sure those are lined up, and you should be all set!

Try out Chipper CI!
Chipper CI is the easiest way to test and deploy your Laravel applications. Try it out - it's free!