node.jsnpmhomebrewnpm-installhomebrew-cask

npm WARN: npm does not support Node.js v12.4.0


I've been getting the following warnings lately whenever I run any npm script:

npm WARN npm npm does not support Node.js v12.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/

It says that I should upgrade to a newer version, but v12.4 is the newest version. Even though the scripts run fine, I think there's no guarantee and something might break at any moment.

I've also tried updating npm in case there's a newer version using npm install npm -g but got the error:

npm ERR! path /usr/local/Cellar/node/12.4.0/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'] {
npm ERR!   stack: 'Error: EACCES: permission denied, access ' +
npm ERR!     "'/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

Then I've seen that Homebrew version of npm can't be updated using npm itself, so I tried updating through Homebrew using brew upgrade npm but got this error:

Error: npm 12.4.0 already installed

For some reason Brew mixes up nodes and npms versions.

What am I doing wrong and how can I get rid of this warning?


Solution

  • Seems like you messed up with permissions in /usr/local.

    Here is how to fix that:

    1. Fix /usr/local permissions:

      sudo chown -R `id -un`:`id -gn` /usr/local
      
    2. Clean npm cache and uninstall it:

      npm cache clean -f
      npm -g uninstall npm
      
    3. Reinstall node (with npm)

      brew reinstall node
      
    4. Upgrade npm:

      npm -g i npm
      

    That should bring npm@6.9.2.

    You should avoid using sudo while installing software with brew or npm, that could cause issues like this.