node-pre-gyp ERR! build error | yarn install | Rails | Mac – Mojave

I encountered a series of errors when I tried to run my existing Rails5 app in my freshly installed macOS Mojave.

$ bundle exec rails s

this generated some errors like, node not found, then I installed node using brew.

$ brew install node

then,

$ npm install yarn
$ yarn install 
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/john/projects/sifaris/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:256:12)
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/Cellar/node/12.1.0/bin/node" "/Users/john/projects/sifaris/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/john/projects/sifaris/node_modules/node-sass
gyp ERR! node -v v12.1.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
$ bundle exec rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
error Lockfile does not contain pattern: "yarn@^1.15.2"
error Couldn't find an integrity file
error Found 2 errors.


========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================

Solution

$ rm yarn.lock
$ yarn cache clean
$ yarn install
$ yarn install v1.15.2

now it installs all the dependencies properly

bundle exec rails s
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
yarn install v1.15.2