Angular-cli: ng --version errors without node_modules dir

Created on 18 May 2018  Â·  7Comments  Â·  Source: angular/angular-cli

Versions

debian jesse FROM node:latest

$ node --version
v10.1.0
$ npm --version
5.6.0
success Installed "@angular/[email protected]" with binaries

Repro steps

Using GitLab CI:

image: davidkassa/yarn-angular-cli-firebase-tools:latest
before_script:
 - node --version
 - npm --version
 - ng --version

Observed behavior

$ ng --version
ENOENT: no such file or directory, scandir '/builds/davidkassa/shot-club-web/node_modules'
Error: ENOENT: no such file or directory, scandir '/builds/davidkassa/shot-club-web/node_modules'
    at Object.fs.readdirSync (fs.js:875:3)
    at VersionCommand.run (/usr/local/share/.config/yarn/global/node_modules/@angular/cli/commands/version.js:48:19)
    at /usr/local/share/.config/yarn/global/node_modules/@angular/cli/models/command-runner.js:278:30
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/share/.config/yarn/global/node_modules/@angular/cli/models/command-runner.js:4:58)
ERROR: Job failed: exit code 1

Desired behavior

I would expect version information to be given even if there is not a node_modules/ directory present

Mention any other details that might be useful (optional)

angulacli high broken bufix

Most helpful comment

I had the same issue and solved it by changing to the root directory [cd ~/] and then running ng --version

All 7 comments

I am getting that same error:

ENOENT: no such file or directory, scandir '/Users/david/repos/halo/frontend/node_modules'
Error: ENOENT: no such file or directory, scandir '/Users/david/repos/halo/frontend/node_modules'
    at Object.fs.readdirSync (fs.js:904:18)
    at VersionCommand.run (/Users/david/.config/yarn/global/node_modules/@angular/cli/commands/version.js:48:19)
    at /Users/david/.config/yarn/global/node_modules/@angular/cli/models/command-runner.js:278:30
    at Generator.next (<anonymous>)
    at fulfilled (/Users/david/.config/yarn/global/node_modules/@angular/cli/models/command-runner.js:4:58)
    at <anonymous>

The only cause I can think of is of mixing both npm and yarn to install/uninstall packages?

I have been unsuccessfully trying to upgrade from angular 5 to angular 6. Now I am trying to do a fallback. Nothing is working

I am getting this error on my WIndows dev box when calling ng --version or ng version...

I have the same problem, but the error message is different. In my case, @angular/cli was installed globally with yarn instead of npm. This command is run from VSCode terminal window. Is this a powershell compatibility issue?

PS C:\Users\mlang> ng --version
At C:\Users\mlang\AppData\Local\Yarn\bin\ng.ps1:5 char:13
+     *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+             ~
Unexpected token ')' in expression or statement.
At C:\Users\mlang\AppData\Local\Yarn\bin\ng.ps1:8 char:3
+ if [ -x "$basedir/pwsh" ]; then
+   ~
Missing '(' after 'if' in if statement.
At C:\Users\mlang\AppData\Local\Yarn\bin\ng.ps1:8 char:5
+ if [ -x "$basedir/pwsh" ]; then
+     ~
Missing type name after '['.
At C:\Users\mlang\AppData\Local\Yarn\bin\ng.ps1:9 char:20
+ ... asedir/pwsh"  "$basedir/../Data/global/node_modules/.bin/ng.ps1" "$@"
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '"$basedir/../Data/global/node_modules/.bin/ng.ps1"' in expression or statement.
At C:\Users\mlang\AppData\Local\Yarn\bin\ng.ps1:9 char:71
+ ... asedir/pwsh"  "$basedir/../Data/global/node_modules/.bin/ng.ps1" "$@"
+                                                                      ~~~~
Unexpected token '"$@"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

It does work from within cygwin or the windows command prompt

C:\WINDOWS\system32>ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.1
Node: 10.15.0
OS: win32 x64
Angular:
...

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

Should this be reported in a separate bug report, related to powershell compatibility?

I had the same issue and solved it by changing to the root directory [cd ~/] and then running ng --version

This happens in yarn 2 plug-n-play set ups as well, because there's no longer a node_modules folder in projects using yarn 2.

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brtnshrdr picture brtnshrdr  Â·  3Comments

rwillmer picture rwillmer  Â·  3Comments

donaldallen picture donaldallen  Â·  3Comments

IngvarKofoed picture IngvarKofoed  Â·  3Comments

sysmat picture sysmat  Â·  3Comments