'ionic' is not recognized as an internal o

2020-05-23 13:41发布

问题:

I have successfully installed Ionic. In fact, I have ran it many times already and it worked perfectly fine (on my browser using "ionic serve" command).. But when I have not done "Ionic stuffs" for a few days, and tried doing it this morning, the command is now unrecognized. What is wrong with this?

回答1:

Running Windows 7 and ran into this issue myself. I ensured that I was running my command line as Administrator, cleaned the cache as suggested but continued to get the error that 'ionic' is not recognized...

After trying several other suggestions, I finally browsed to my nodejs location: C:\Program Files\nodejs

I ran the nodevars.bat to open the nodejs command prompt, ran the ionic command and everything worked as expected. I'm not sure what the issue is but running command from that .bat file appears to fix it.



回答2:

I added this the path and all worked well.

%APPDATA%\npm;



回答3:

I already solved it. :) For some unknown reason my ionic installation went MIA. And I didn't solve that directly, it had errors that says "Run as Administrator", etc when in fact I'm running Admin... The trick was to clean the cache before reinstalling Ionic using the npm cache clean command.



回答4:

It had errors that says:

Run as Administrator

etc, when in fact I'm running as Admin... The trick was to clean the cache before reinstalling Ionic using the command:

npm cache clean

It worked for me. Just run npm command for cache clean and reinstall the ionic as:

npm install -g ionic

and it works perfectly fine.



回答5:

After a couples days of this exact issue, I found my solution. Remove all of corodva with npm uninstall cordova and ionic with npm uninstall ionic. Then clear the cache with npm cache clear. View this for full removal https://stackoverflow.com/a/29429357/5144902

I then found that there was a couple folders still in my C:\Users\USERNAME\AppData\Roaming\npm. I could not remove this, as the file extension was too long. I opened cmd, and removed it with the DEL command. I then found that a node_modules folder was under my user folder. I removed that.

Then Global install with npm install -g ionic cordova. Works perfectly.



回答6:

None of the solutions worked as permanent fix for me and it was pretty disgusting to use a fix every time I intended to use ionic. So, while browsing for a solution, I read some solutions that eventually led to this: Go to your system settings->Advanced system settings->environment path. In my case, while the 'npm' was indeed added to the system path, it was separated by a single comma inspite of a colon (;). So, I replaced it with a colon and bingo! Please do restart your CMs before trying to test it. Hope it helps!



回答7:

If you are on Windows, use Git Bash shell and have issues calling cordova and ionic, maybe you'll have to add a path value to

c:\users[your username].bash_profile

this helped comparing windows path (cmd - echo %path%) with git bash shell path:

Git Bash doesn't see my PATH

for me, global paths were there, but user paths not. I had to add:

PATH=$PATH:/c/Program Files (x86)/Microsoft VS Code/bin:/C/Users/[my username]/AppData/Roaming/npm



回答8:

Go to nodejs installed directory ( in my case it's C:\Program Files\nodejs), then run the bat script "nodevars.bat" with administator permission. That solves my problem.



回答9:

In the Windows environment, when we install packages with -g option they are not available sometimes while running the package through the command prompt. Steps below that worked for me —

Create a .npmrc file at C:\Users{username}\

Write below line in the .npmrc file. Write path as per the location of nodejs installed in your machine. Add double back slash wherever you have a back slash in the path.

prefix="D:\\programs\\nodejs"

Run the command to install the package again

npm install -g ionic

Run the new command

ionic serve


回答10:

Variable Name: Path

Variable value: C:\Program Files\nodejs\bin

Try adding this to your user and environment variables , and then close the command prompt window and open. The bin folder needs to be given for both user and environment variables I got my problem resolved :)



回答11:

You can uninstall as

npm uninstall -g ionic cordova

then clear cache

npm cache clean -f

then re-install as

npm install -g ionic cordova


回答12:

answer here

İf "ionic" is installed;

1-Download and upgrade nodejs to latest version. download nodejs

2- run command:

npm uninstall -g ionic

3-Clear these files:

C:\Users\user\AppData\Roaming\npm

C:\Users\user\AppData\Roaming\npm-cache

3-run command:

npm install -g @ionic/cli

İt is done:)



回答13:

Just go to your C:/users/(your name)/node_mudules, and uninstall node_mudules folder. Once uninstalled, open up node js command prompt and type npm install -g ionic cordova this worked for me