Failing to build angular-cli app because of node-sass needed to be rebuild

angular
cli

#1

Hi everyone,

I was trying to setup a CI of a fresh angular-cli project.
Followed the docs and some additional posts and got it running(ish).

At the step of tests execution
npm run test

I was getting the following error:
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 6.x

Found bindings for the following environments:
  - Linux 64-bit with Node.js 7.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 (/home/circleci/repo/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/home/circleci/repo/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/circleci/repo/node_modules/sass-loader/lib/loader.js:3:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17),Module build failed: Error: Missing binding /home/circleci/repo/node_modules/node-sass/vendor/linux-x64-48/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 6.x

After researching some more, I added this step:
- run: npm rebuild node-sass --force
just before the tests.

Everything started to work, however, this rebuild process takes most of the time (and pretty long time)
Is it actually necessary? How do I avoid it? What is the better way of doing it?

My config.yml is:

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:6.10-browsers

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout

      # Log the current branch
      - run:
          name: Show current branch
          command: echo ${CIRCLE_BRANCH}

      # Restore local dependencies from cache
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            - v1-dependencies-

      # Install project dependencies
      - run:
          name: Install local dependencies
          command: npm install

      # Cache local dependencies if they don't exist
      - save_cache:
          key: v1-dependencies-{{ checksum "package.json" }}
          paths:
            - node_modules

      # Lint the source code
      - run:
          name: Linting
          command: npm run lint


      - run: npm rebuild node-sass --force

    # Test the source code
      - run:
          name: Testing
          command: npm run test

#2

There seems to be quite a few answers on Stack Overflow, are any of these any good?


#3

This is exactly where I found this: - run: npm rebuild node-sass --force
But, my question was, how do I get rid of this step and why is it happening in a first place?


#4

Hi,

I came across this problem in Circle CI whenever I restored the dependency cache. I haven’t delved into why the error happens when the cache is restored. However, the command I have been running is npm rebuild node-sass without the --force flag. The flag doesn’t seem to be documented for the npm rebuild command; but it is in the documentation for the npm install command:

The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk.

When using the command without the flag, npm may find the binding it needs. In this case the build step runs for 3 seconds and the output looks like this:

I’ve put the full configuration I’m using up on GitHub at https://github.com/CharlesSuttie/angular-cli-circle

cheers,
Charlie


#5

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.