Fixing "fsevents" deployment errors on Heroku

HomeProgramming

Experiencing issues deploying your node based web application on Heroku?

Have you gotten an error that looks similar to this one?

error fsevents@1.2.7: The platform "linux" is incompatible with this module.

You're not the only one. Luckily, I've done the hair pulling for the both of us, so you'll be back in business in no time.

To prevent this error from disrupting your build, simply update your package.json file to mark fsevents as an optional dependency.

{
  "optionalDependencies": {
    "fsevents": "2.1.2"
  },
}

Why does this work?

Mac users frequently use fsevents to assist with local development, especially for hot-reloading and automatic code reloading.

Because fsevents is only meant to be installed on MacOS, listing it in your package.json will only present issues once you attempt to deploy your application to Heroku. Because Heroku attempts to build your application on a Linux based system, you'll encounter the above error, which will stop the build.

By listing fsevents as an optional dependency, the Heroku build process understands it can continue with your build even when the installation of this package fails.

Written by
Daniel Ternyak