node.js – npm broken after update

I just updated npm using npm install -g npm@latest, because I installed a package that required a newer version.
Now when I run any npm command, even npm --version, I get the following error:

ERROR: npm v10.2.4 is known not to run on Node.js v14.15.4.  This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

ERROR:
C:\Users\suitendaal\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\agent\lib\agents.js:105
    options.lookup ??= this.#options.lookup
                   ^^^

SyntaxError: Unexpected token '??='
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\suitendaal\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\agent\lib\index.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

I already found items on stackoverflow about using nvm to install versions of NodeJS, but apparently I am not using this (I installed it years ago and don’t remember how). My OS is Windows.
How do I fix this error and install the correct versions of npm and NodeJS?

Read more here: Source link