Troubleshooting Rails5 App Startup Issues on macOS Mojave - gyp ERR! build error

Encountering errors while running your existing Rails5 app on a freshly installed macOS Mojave can be frustrating. Here’s a detailed guide to help you troubleshoot and resolve these issues.

Error Messages and Initial Steps

When trying to start the Rails server using bundle exec rails s, you encountered a series of errors. Initially, there were issues with node not being found. This was resolved by installing node using brew.

$ brew install node

Following this, you proceeded to install yarn and ran into more errors during the installation process. One of these errors indicated a build failure related to gyp.

Addressing GYP Build Error

The error related to gyp during yarn installation usually stems from a build failure. Let’s delve into the solution to this issue.

gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
...
gyp ERR! not ok

Solution: Rebuilding Dependencies

To resolve the gyp build error, we need to rebuild the dependencies.

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

This process should now install all the dependencies properly, addressing the build error.

Updating Yarn Packages

Subsequently, when attempting to start the Rails server, you encountered errors related to outdated Yarn packages.

Lockfile does not contain pattern: "yarn@^1.15.2"
...
Your Yarn packages are out of date!
Please run `yarn install --check-files` to update.

Updating Yarn Packages

To update the Yarn packages and resolve these errors, run the following command:

$ yarn install --check-files

Now, you should be able to start the Rails server without encountering any Yarn-related issues.

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

Conclusion

By following these steps and addressing the specific error messages, you should have resolved the startup issues for your Rails5 app on macOS Mojave. Troubleshooting and updating dependencies are crucial steps to ensure smooth application development.