I tried to update my cordova using npm update -g cordova but encountered the following error:

internal/modules/cjs/loader.js:611
    throw err;
    ^

Error: Cannot find module 'node:path'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:609:15)
    at Function.Module._load (internal/modules/cjs/loader.js:535:25)
    at Module.require (internal/modules/cjs/loader.js:663:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\Asus\AppData\Roaming\npm\node_modules\npm\lib\cli.js:2:18)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)

Simple fixes didn’t help, so I used the following method.

STEP 1

Windows

  1. Download and install NVM: https://github.com/coreybutler/nvm-windows/releases/latest
  2. Check it in CMD “nvm version”

MacOs/Linux

  1. wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  2. command -v nvm

STEP 2

Install Nodejs

Linux

nvm install node
nvm install --lts

or Windows

nvm install node
nvm install lts

Check it via command nvm ls

Step 3

Changing the NPM version

nvm use %version%

Step 4

npm work! now update cordova

npm update -g cordova
npm install cordova

but it didn’t work out the first time

C:\Users\Asus>npm install cordova
npm warn old lockfile
npm warn old lockfile The package-lock.json file was created with an old version of npm,
npm warn old lockfile so supplemental metadata must be fetched from the registry.
npm warn old lockfile
npm warn old lockfile This is a one-time fix-up, please be patient...
npm warn old lockfile
npm warn deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
npm warn deprecated [email protected]: this library is no longer supported
npm warn deprecated [email protected]: This module is not used anymore, and has been replaced by @npmcli/package-json
npm warn deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm warn deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

added 545 packages, and removed 1 package in 56s

62 packages are looking for funding
  run `npm fund` for details

C:\Users\Asus>cordova -v
(node:17848) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17848) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'find' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'head' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'set' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'test' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'to' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency
(node:17848) Warning: Accessing non-existent property 'which' of module exports inside circular dependency
8.1.2 ([email protected])

Let’s do it again

npm update -g cordova
npm fund
cordova -v

it’s work!

Categorized in:

Tagged in:

, ,