I'm trying to install ionic on Windows but for some reason, I'm unable to. When I run the "npm install" everything looks fine, no errors, nothing weird happens, however when I try to run "ionic start" (or any ionic command, even just ionic -version) the shell says that "ionic is not recognized as an internal or external command".
I've tried everything but obviously, I'm still doing something wrong something. I tried uninstalling/re-installing/updating everything I could so I'm pretty sure that Nodejs and npm are fine.
From what I read online I found that this kind of error happens when the environmental variables are messed up, however, I don't exactly know what I'm supposed to change there. I've followed many guides and tutorials: some of them said that the PATH to npm should be under 'Roaming', others said that the PATH should be under 'Local', some said that it should be in 'Program Files' and others said that what matters is the order in which you write the PATH variables.
Some just said to reinstall node and after that everything should be fine but none of these suggestions worked.
Can anyone help me? What kind of environmental variables do I need to put in for this to work?
Should I remove the node and start from scratch? If so, where should I install node so that I don't have weird path problems later on?
If you need any additional information on the problem please say so. Thank you in advance for your time
It looks like your npm packages are not being installed on the default npm folder (%appdata%\npm). There's this command that shows you the root global npm folder, you can run npm root -g to check where npm is installing the packages and add that path to your PATH environment variable.
First, run the command bellow:
C:\> npm root -g
It will give you a path like this:
C:\my\actual\path\node_modules
Grab the path without node_modules (C:\my\actual\path\), and then add it to your PATH environment variable.
Warning: don't forget to remove the node_modules from the path it gave you.
Once you set your PATH variable, you need to restart your computer.
When I run sudo npm install -g express-generator:
/Users/myname/npm/bin/express -> /Users/myname/npm/lib/node_modules/express-generator/bin/express-cli.js
/Users/myname/npm/lib
└── express-generator#4.15.5
And when I run express:
express not found
Also, I thought it was interesting that when I run which npm:
/usr/local/bin/npm
That is the path.
It seems that whenever I try to install something like yeoman or this express generator globally, it never works.
It should also be noted that I am on an Mac running zsh.
Most likely your npm bin directory is not in the path. Try to list the files in that directory by ls -l /usr/local/share/npm/bin/.
If you find the express file, you can add that directory to the path by export PATH=/usr/local/share/npm/bin:$PATH. If not, most likely something went wrong with your installation and you can try installing the module again.
Running this in the command line:
export PATH=/usr/local/bin/npm:$PATH
Fixed the issue...for now. I'm not totally sure why that worked.
This affects Homebrew users using Node.js & npm
When you install Node.js using Homebrew it does not put npm on the PATH for you, however it suggests that you should do so.
Homebrew doesn't modify the user's environment or dotfiles. However, brew install node does print a message suggesting the user add that path to their PATH.
Source
There was another issue open with the same title which has been closed but my error could not be resolved using the solutions given in that issue.
Mac OSX El Capitan
Node [v5.6.0]
Npm [v3.6.0]
I installed Browser-Sync successfully using :
bash
$ sudo npm install -g browser-sync
but when I check the browser-sync version by typing :
bash
$ browser-sync --version
I get this error :
bash
-bash: browser-sync: command not found
Check where npm installs it's binaries by running npm bin -g, and then add that to your PATH.
export PATH=$PATH:/usr/local/bin
None of this was helpful to me, instead what I did was find the file location of browser sync after i executed the browser-sync download command supplied on their website. npm install -g browser-sync
Turns out my windows 10 put that downloaded file into %appdata% folder which is in Local Disk (C), but it's an invisible folder and not the correct place it should be, it needs to be in the nodejs folder inside Program Files...
So to find this folder do this: in the search bar of windows 10 type in %appdata% and press Enter, it should open up that hidden folder...
Then click on npm > npm_modules > then you should see files saying browser-sync. Highlight and drag all those files into Local Disk (C) > Program Files > nodejs. You will get allow access prompts, just allow all those.
Now browser-sync and nodejs are sitting happily together and NOW, you can go back to your CMD window and type in browser-sync --version and get the correct version.
I am taking the Coursera class titled HTMl, CSS, and Javascript for Web Developers and ran into this very problem and this solution made it possible for me to continue setting up my environment to take the class.
Although above answers are correct, there is an easy way to handle this. Instead of explicitly creating $PATH we can install Browsersync globally.
npm i -D browser-sync
Here -g option specifies npm to install browser-sync package globally and add $PATH automatically. Next check wether it is working or not by running:
browser-sync --version
Note: Even if you already installed Browsersync try running this. The issue will be resolved.
This question already has an answer here:
NPM -bash command not found
(1 answer)
Closed 6 years ago.
Using a Mac Os X Yosemite was trying generate some scaffolding and this is what comes back in the bash terminal
-bash: some_command: not found
This happens with most of my commands like run, serve etc when trying to generate or use certain executable commands. General alias’s and commands like mv, ls, rm etc work fine
I’ve checked my $PATH and it seems correct:
$ /bin/echo $PATH
/Users/user_name/.rbenv/shims:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/heroku/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/Users/user_name/.rbenv/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin
I checked to make certain npm, node, yomen, grunt etc show as installed with -v and shows updated and installed.
I’ve checked my ~.bash_profile appears and aliases but all seems fine.
The best I can gage is it has something to do possibly with npm and or Node and possibly Homebrew. So I’ve uninstalled, reinstalled and researched any similar like questions out there but nothing seems to work. Hoping someone can point me in the right direction here since I am at a lost. And I am not the best at the environment set up. So might not be looking at something thats staring at me in the face. Thanks in advance.
Make sure to install whatever CLI tool you're trying to use first if you haven't already. For example:
npm install -g yo
That command installs yeoman into the global npm module directory. That directory should also be in your $PATH. To find the directory npm uses, type the following:
npm config get prefix
That will show you what directory npm is installing global modules to. In that directory there should be a bin/ directory with symlinks for any CLI tools that came with a global module you installed. That bin/ directory should be in your $PATH variable for bash to find command line scripts in there.
I'm using NVM to manage my node installations so when I run npm config get prefix my directory is: /Users/chev/.nvm/versions/node/v5.0.0. That's not the standard directory though. If you installed node with the default installer then yours will be different. When I do echo $PATH mine looks like this: /Users/chev/.nvm/versions/node/v5.0.0/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin. Directories in path are separated by colons (:).
A common problem with node on OSX is the need to use sudo with npm commands because of permissions issues in the default global npm modules directory. If you're having issues like that I suggest you also start using something like NVM. NVM allows you to install multiple node versions side by side, but even if you don't need that functionality it's still useful because it configures node & npm so that everything operates out of your home directory at ~/.nvm/ and avoids permission issues. No more sudo.
Okay I am running node on windows (7). Using npm I just installed modules to d:\ directory. Therefore my files structure looks like the following:
D:\
-myproject
-node_modules
-.bin
-express
However, when I am in this 'myproject' directory, I can't seem to run 'express' for example:
D:\myproject\express site
'express' is not recognized as an internal or external command, operable program or batch file.
Am I doing anything wrong?
Try:
npm install -g express-generator#3
That solved problem for me.
Edit: for version 4
npm install express-generator -g
Description:
express is the package for dependency of express js.
express-generator is the package for enabeling express command and create a sample project, etc.
Assuming that this is kept separate for the decoupling of project dependency with cli tool of express.
Another SO ref: https://stackoverflow.com/a/41311733/1666582
Here's what to type in the command line to make it work in windows:
npm install express-generator -g
[Source: http://expressjs.com/starter/generator.html]
My guess is that you didn't install Express globally. You can install express globally (and therefore available in your PATH) with the following command (see http://expressjs.com/guide.html) :
npm install -g express
The way you install it is available only in the folder that you installed it and there is nothing wrong with that approach. There is very little advantage of having it available globally.
If express is not in your PATH you can run it by entering the full path to it:
\myproject\node_modules\.bin\express.cmd
With the release of Express 4.0.0 it looks like you need to do
npm install -g express-generator
We need to set path for express global directory
C:\Users[User_Name]\AppData\Roaming\npm\
After add a new path, please reopen the CMD console
Tried all of these and never worked. A repair of Node.js by kicking of installation and selecting repair option does the magic.
Cheers
What worked for me was:
I used the windows command prompt instead of the node.js command prompt.
In windows 10 simply type in the windows search bar for "node"
You see a node.js desktop app and a node js command prompt.
Choose the "node js command prompt"
Type in the command prompt
npm install express-generator -g
Then navigate somewhere and type in:
express your-website-text-here -e
A directory with express files will be generated. Also now you won't see the express error.
I was able to fix with the following package install:
npm install express-generator -g
Thanks
When you install Node.js, the below path is added to the Windows OS %Path% variable, I'm presuming similar happens on other operating systems as well:
C:\Users\<your-windows-username>\AppData\Roaming\npm
In my case, because I use a work Windows laptop for an employer that severely restricts what employees can do on their machines (I.e. many actions require elevated admin privileges), Node.js was being prevented from adding the above path to the Windows %Path% environment variable, and much to my chagrin the Node.js installation was silent about it. Navigate to above folder and you will notice the express command lives there, see screenshot below.
How did I figure this out? I did a fresh installation of Node.js on a personal, home Windows machine that has no admin privilege restrictions like my work machine does, compared the before and after %Path% value, and noticed the addition of that path. My work machine was missing it.
I had no choice but to add the path manually to %Path%, and then express was recognized from within any path I ran it.
I was able to fix this with:
npm install express-generator -g
I tried all the above solution, no luck for me.
Open "Node.js" command prompt and tried as administrator. It is working fine for me. Don't try with windows command prompt.
I have the same problem and understand the solution, but i can´t undestand why, running npm install -g express, express.bat isn´t added automatically to Path.
Running with npm install -g express have the same result. Download packages and store in node_modules, but express.bat isn´t added to path.
Run the node command prompt as administrator and then install express globaly
npm install -g express
and then go to folder where you want to install express generator, open command prompt there and run this command
npm install express-generator, it will then fix the issue
I have tried out all above solutions, but its did't worked for me, finally I have re-installed the node.js with newer version and started to express install process again. Its worked for me.
npm install -g express
npm install -g express-generator
What command are you using to open the directory?
That error means CMD can't find the "express" executable in the current directory.
Use the "PUSHD" command or "CD /D" instead of "CD"
#Echo OFF
PUSHD "D:\myproject\express" || (Echo bad folder)
express.exe "site"
Pause&Exit
Express is loaded someplace else and not in the windows path environment variable. You need to find were express.exe is installed and add the path. Maybe something like ;"C:\Program Files\Express\bin";
Running "npm install express" and "npm install express-generator" from your project directory will resolve the issue (if that helps).
But, this doesn't solve the problem of being global.
You might check the permissions to the folder if you are getting this when creating your project
Express Project
change script section in package.json file like this
"scripts": {
"start": "node app.js"
}
I too faced the similar problem and at last I tried using node.js command prompt instead of windows command prompt and it worked. So, try from node.js command prompt.
Tried all of these but didn't work for me. Also, I tried from different sources but never worked for me.
In the end, found that I need to run the command forcefully. It worked for me.
Make sure you run the command with Run as Administrator.
npm install -g --force express-generator
It will overwrite the existing express files.
Use npm start .. then the app.js runs .. which can be listened on the usual port 3000