GitHub Action running npm build fails on warnings

On a new GitHub Action I’ve added on a React project, the npm run build is failing because apparently GitHib Actions treat warnings as errors:

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.

Following advice on questions to this post, adding CI=false to the ‘npm run build’ script in package.json turns off this behavior:

    "predeploy": "CI=false && npm run build",

GitHub Action npm i fails when package.json includes fsevents

I’ve added a GitHub Action to a project, and when it runs on a push I get this error:

Run npm ci
npm ERR! notsup Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin"} (current: {"os":"linux","arch":"x64"})
npm ERR! notsup Valid OS:    darwin
npm ERR! notsup Valid Arch:  undefined
npm ERR! notsup Actual OS:   linux
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-09-11T23_52_20_527Z-debug-0.log
Error: Process completed with exit code 1.

fsevents is installed/added when doing ‘npm i’ as a dependency when building on MacOS, but it is MacOS specific, and since it’s included in my package.json it’s causing the build on GitHub to fail. Apparently according to this post, it can be optionally included on platforms where it’s available/needed by moving it from the dependencies section in package.json to optionalDependencies instead:

  "optionalDependencies": {
    "fsevents": "^2.3.2"

This resolved my issue, my GitHub Action now runs.

Managing and switching node versions with nvm

If you’re working on multiple projects with different node versions, switching versions can get tricky. nvm is a version manager for node that allows you to easily switch between versions. For example, I have a later non-LTS version installed, but to avoid issues like this one that I run into with later versions:

opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',

… I need to switch back to the current LTS version to avoid this error. This is easy with:

nvm use --lts