-1

After upgrading to the latest Node and npm version, when I try any npm command, I get the following error:

 C:\Users\...>npm doctor
    TypeError: Cannot read property 'prefix' of undefined
        at parseField (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\parse-field.js:15:43)
        at Config.parseField (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:438:12)
        at Config.[loadObject] (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:430:24)
        at Config.loadDefaults (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:268:22)
        at Config.load (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:207:10)
        at Object.[_load] (C:\Users\...\npm\node_modules\npm\lib\npm.js:176:23)
    Error: call config.load() before reading values
        at Config.get (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at errorHandler (C:\Users\...\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at Object.<anonymous> (C:\Users\...\npm\node_modules\npm\lib\cli.js:42:14)
        at Object.onceWrapper (events.js:422:26)
        at Object.emit (events.js:315:20)
        at C:\Users\...\npm\node_modules\npm\lib\npm.js:148:12
    Error: call config.load() before reading values
        at Config.get (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at process.errorHandler (C:\Users\...\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at process.emit (events.js:315:20)
        at processPromiseRejections (internal/process/promises.js:245:33)
        at processTicksAndRejections (internal/process/task_queues.js:94:32)
    C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163
          throw new Error('call config.load() before reading values')
          ^
    
    Error: call config.load() before reading values
        at Config.get (C:\Users\...\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at process.errorHandler (C:\Users\...\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at process.emit (events.js:315:20)
        at process._fatalException (internal/process/execution.js:163:25)

Running command npm -v and npm outdated returns the same error.

I run cmd as administrator.

Environment Variables

User variables for ...

enter image description here

System variables

enter image description here

Running command

C:\Users\...>node --version

returns

v14.16.1

I use Angular 7 and ng build seems to work as usual.

Giannis
  • 1,790
  • 1
  • 11
  • 29
  • I tried to delete it but could not. I followed the recommended way (to edit the question) from the proposed article. Please let me know if there is another way. – Giannis Jul 07 '23 at 10:47

2 Answers2

0

Once I had the same problem. Be it any command, Node was throwing an error. After some research I found the solution which was a complete uninstall and removal of Node from my system and then a reinstallation of a fresh version.

Consider this answer to completely remove Node from the system: How to completely remove node.js from Windows

Kashish Khullar
  • 394
  • 1
  • 3
  • 14
  • I uninstalled and re-installed Node from Apps&Features, but the error still remains the same. Also, cannot run step 1 of the recommended answer (npm cache clean --force). – Giannis Apr 07 '21 at 09:00
  • Did you try removing the cache files? Also did you try changing the installation directory? Do update the PATH in env variables. – Kashish Khullar Apr 09 '21 at 12:48
  • Thank you. I tried both, but nothing changed. I also tried to repair the Nodejs installation with no success. The problem was the npm folder inside node_modules. Hopefully, I managed to solve it by using another npm folder. – Giannis Apr 09 '21 at 13:20
-1

Actually you don't have to re-install it, just change the node version with nvm.

some node version doesn't compatible with npm ver. ,

so first of all, check out your node version and then change your current node version to compatible with your npm version with node version manager(nvm).