angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.73k stars 11.98k forks source link

global `ng version` shows errors instead of version numbers #10523

Open StephenFluin opened 6 years ago

StephenFluin commented 6 years ago

Versions

Angular CLI: 6.0.0-rc.7
Node: 9.9.0
OS: linux x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    <error>
@angular-devkit/core         <error>
@angular-devkit/schematics   <error>
@schematics/angular          <error>
@schematics/update           <error>
rxjs                         <error>

Repro steps

yarn global add @angular/cli@next
ng version

Observed behavior

Package                      Version
------------------------------------------------------
@angular-devkit/architect    <error>
@angular-devkit/core         <error>
@angular-devkit/schematics   <error>
@schematics/angular          <error>
@schematics/update           <error>
rxjs                         <error>

Desired behavior

Hide the errors if these packages are not supposed to be installed, or show me the version numbers.

rapric2115 commented 6 years ago

I did have the same problem, what I did and work for me was uninstall angular globally, npm uninstall -g @angular/cli and installed again npm install -g @angular/cli@latest. And got all package installed without errors. Hope works for you too.

hasanslayer commented 6 years ago

change to the directory that have package.json I think called ClientApp then try to run ng -v that worked for me.

yfain commented 6 years ago

Uninstall and installed Angular CLI 6.1.1 globally. Running ng version from a random directory crashes with the error stating that the node_modules can't be found. Changed directory to one of my project that had node_modules and ng version started working fine. This is clearly a bug.

theNotoriousHxc commented 6 years ago

I'm also experiencing this one.

If it's the expected behaviour then why should it only work when you're under an angular project when i should only be concerned with querying the version of angular-cli?

9034725985 commented 6 years ago

This looks somewhat related. The failure only happens with yarn global add but not with npm -g install. What could be the cause?

I tried this with Windows as well as KDE Neon (basically Ubuntu 16.04 Xenial) and it seems to be this way in both places.

neon@neon:~$ nvm --version
0.33.11
neon@neon:~$ nvm install node
Downloading and installing node v10.10.0...
Downloading https://nodejs.org/dist/v10.10.0/node-v10.10.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.10.0 (npm v6.4.1)
Creating default alias: default -> node (-> v10.10.0)
neon@neon:~$ node --version
v10.10.0
neon@neon:~$ npm --version
6.4.1
neon@neon:~$ npm -g install yarn
/home/neon/.nvm/versions/node/v10.10.0/bin/yarn -> /home/neon/.nvm/versions/node/v10.10.0/lib/node_modules/yarn/bin/yarn.js
/home/neon/.nvm/versions/node/v10.10.0/bin/yarnpkg -> /home/neon/.nvm/versions/node/v10.10.0/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.9.4
added 1 package in 0.527s
neon@neon:~$ yarn --version
1.9.4
neon@neon:~$ which yarn
/home/neon/.nvm/versions/node/v10.10.0/bin/yarn
neon@neon:~$ yarn global add @angular/cli
yarn global v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Installed "@angular/cli@6.2.2" with binaries:
      - ng
Done in 5.21s.
neon@neon:~$ ng --version
The program 'ng' is currently not installed. You can install it by typing:
sudo apt install ng-common
neon@neon:~$ yarn global bin
/home/neon/.yarn/bin
neon@neon:~$ cat ~/.bash
.bash_history  .bash_logout   .bashrc        
neon@neon:~$ cat ~/.bashrc 
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
neon@neon:~$ vim ~/.bashrc 
neon@neon:~$ source ~/.bashrc 
neon@neon:~$ which ng
/home/neon/.yarn/bin/ng
neon@neon:~$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 6.2.2
Node: 10.10.0
OS: linux x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    <error>
@angular-devkit/core         <error>
@angular-devkit/schematics   <error>
@schematics/angular          <error>
@schematics/update           <error>
rxjs                         <error>

neon@neon:~$ yarn global remove @angular/cli
yarn global v1.9.4
[1/2] Removing module @angular/cli...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
Done in 0.40s.
neon@neon:~$ which ng
neon@neon:~$ npm -g install @angular/cli
/home/neon/.nvm/versions/node/v10.10.0/bin/ng -> /home/neon/.nvm/versions/node/v10.10.0/lib/node_modules/@angular/cli/bin/ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/@angular/cli/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ @angular/cli@6.2.2
added 241 packages from 190 contributors in 16.175s
neon@neon:~$ which ng
/home/neon/.nvm/versions/node/v10.10.0/bin/ng
neon@neon:~$ ng --version
bash: /home/neon/.yarn/bin/ng: No such file or directory
neon@neon:~$ ls -a 
.   .bash_history  .bashrc  .config  Desktop    Downloads  .gtkrc-2.0  .local    Music  .nvm      .profile  .ssh                       Templates  .viminfo     .xsession-errors  .yarnrc
..  .bash_logout   .cache   .dbus    Documents  .gconf     .kde        .mozilla  .npm   Pictures  Public    .sudo_as_admin_successful  Videos     .Xauthority  .yarn
neon@neon:~$ vim ~/.bashrc 
neon@neon:~$ source ~/.bashrc 
neon@neon:~$ which ng
/home/neon/.nvm/versions/node/v10.10.0/bin/ng
neon@neon:~$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 6.2.2
Node: 10.10.0
OS: linux x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.8.2
@angular-devkit/core         0.8.2
@angular-devkit/schematics   0.8.2
@schematics/angular          0.8.2
@schematics/update           0.8.2
rxjs                         6.2.2
typescript                   2.9.2

neon@neon:~$ 
clydin commented 6 years ago

Yarn’s global installs do not work properly with nvm. Don’t have a link right now but there were several issues on yarn’s repo related to it.

armpogart commented 5 years ago

Can confirm that yarn global install without nvm also causes the same issue.

rikusen0335 commented 5 years ago

I had same issue and it has fixed when I change to correct directory.

dreDevOS commented 4 years ago

did any sole this I tried to install nom global I still get the same error ng command not found when I try to start ng serve or check version can some help me solve this problem I am using a Mac

nicoisz commented 2 years ago

i solved this using the standard registry using npm config delete registry and after that i could install angular globally and then install the dependencies with npm i


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 12.2.17
Node: 16.10.0 (Unsupported)
Package Manager: npm 7.24.0
OS: darwin x64

Angular: 12.2.16
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.17
@angular-devkit/build-angular   12.2.17
@angular-devkit/core            12.2.17
@angular-devkit/schematics      12.2.17
@angular/cli                    12.2.17
@schematics/angular             12.2.17
rxjs                            6.6.7
typescript                      4.3.5