Npm ENOENT error

When I try to add a plugin ionic cordova plugin add <plugin_name> asks me to update Ionic CLI to the latest version, but as I try to update fails with this error:

An error occurred while running npm install --save-dev --save-exact ionic@latest (exit
        code 254):
        
        npm ERR! path
        /home/MyProject/node_modules/cordova-android/node_modules/cordova-common
        npm ERR! code ENOENT
        npm ERR! errno -2
        npm ERR! syscall rename
        npm ERR! enoent ENOENT: no such file or directory, rename
        '/home/MyProject/node_modules/cordova-android/node_modules/cordova-common'
        ->
        '/home/MyProject/node_modules/cordova-android/node_modules/cordova-common.DELETE'
        npm ERR! enoent This is related to npm not being able to find a file.
        npm ERR! enoent

I tried to manually install cordova-common but it returns the same error.
How can I solve this problem?

Your problem is probably with npm, something to do with permissions and files. This happens quite often and is almost impossible to successfully debug (at least here in the forum).

One solution: Uninstall your node, install nvm (or nvm-windows when you are using Windows), install a new node with this, then install ionic and cordova again and try your command again. The problem should be gone.

Thanks a lot for the answer, now fortunately works!

1 Like