Saturday, November 19, 2022

windows: npm: angular: 'ng' is not recognized as an internal command

 

>PROBLEM

Running the command "ng v", returns:

  'ng' is not recognized as an internal command

  'ng' não é reconhecido como um comando interno  (Portuguese)


>SOLUTION


This procedure is about Windows O.S.

After attempting to solve the problem through other experiences, I got no solution.

My Path seemed to be corrupted and there were no files under the user's folder, for instance at:

  C:\Users\<USER>\AppData\Roaming\npm\node_modules


So, to solve the issue, I decided to restart the environment installation from scratch.

This same procedure were executed several times, including restarting the sytem, until the success came. :-)

  1. Uninstall node.js using the windows "Add remove application...".

  2. Remove leftovers. Sometimes there are "skeleton" folder left behind. In my case, it was: C:\Users\<USER>\AppData\Roaming\npm\node_modules

  3. Run the node.js as Administrator. Make sure of that, because it is important.

  4. After the installation is fineshed, check it:
    node --version
    npm --version

  5. Install @angular/cli that it is the lib that provides the "ng" command, as global installation (important: not locally).

  6. The previous command will install the latest version. If you're working with a specific version, go to the angular project's root folder and check the package.json file to verify which version the project is working with: 
    "dependencies": {
     ...
     "@angular/cli": "^13.2.2",  
    ...

  7. Under the project's root folder, install cli using the same version:
    npm install @angular/cli@13.2.2

  8. Eventually, check it the project's env:
    ng v

  9. It shall return the same version used for the project.








>ENV

Angular
Node.js 16


No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...