Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Running `ng version` outside an Angular project has confusing output

未关闭
#16,549 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
angular, typescript
领域
cli

调研方向

services/ng-frontend/ 内部和外部都重现 issue 中的两个 ng version 命令,并跟踪 Angular CLI 版本命令的入口点。当 Angular 项目外部的输出明确表明未检测到项目,且不会让全局版本看起来像项目版本时,此更改就完成了。

由索引模型根据 Issue 内容生成。

描述

area: @angular/cli freq1: low severity1: confusing type: bug/fix

🐞 Bug report

Command
  • update
  • version
Is this a regression?

No

Description

I have a monorepo where I am adding an Angular project. As a result, it exists in a subdirectory. Since many tools (such as ng) expect the project to be the working directory, I often use the pattern (cd path/to/subproject/ && run some tool). The subshell means I'm returned back to my original directory.

This pattern does not play well with ng version and ng update. I was trying to update to version 9 prerelease and saw the following:

$ (cd services/ng-frontend/ && ng update @angular/cli @angular/core --next)
# Successful update...
$ ng version
     _                      _                 ____ _     ___                                            
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|                                           
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |                                            
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |                                            
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|                                           
                |___/                                                                                   
                                                                                                        
                                                                                                        
Angular CLI: 8.3.21                                                                                     
Node: 13.5.0                                                                                            
OS: linux x64                                                                                           
Angular:                                                                                                
...                                                                                                     
                                                                                                        
Package                      Version                                                                    
------------------------------------------------------                                                  
@angular-devkit/architect    0.803.21                                                                   
@angular-devkit/core         8.3.21
@angular-devkit/schematics   8.3.21
@schematics/angular          8.3.21
@schematics/update           0.803.21
rxjs                         6.4.0

This was confusing and made me think the update failed, however the update was actually fine. My mistake here was running ng version in the root of my monorepo, rather than the Angular project. After noticing this I tried:

$ (cd services/ng-frontend/ && ng version)
     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.0-rc.7
Node: 13.5.0
OS: linux x64

Angular: 9.0.0-rc.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.7
@angular-devkit/build-angular     0.900.0-rc.7
@angular-devkit/build-optimizer   0.900.0-rc.7
@angular-devkit/build-webpack     0.900.0-rc.7
@angular-devkit/core              9.0.0-rc.7
@angular-devkit/schematics        9.0.0-rc.7
@ngtools/webpack                  9.0.0-rc.7
@schematics/angular               9.0.0-rc.7
@schematics/update                0.900.0-rc.7
rxjs                              6.5.4
typescript                        3.6.4
webpack                           4.41.2

Which is what I expected post-update.

IMHO this dichotomy is confusing. When the user is in an Angular project, it lists versions of that project. When outside an Angular project, it lists the global versions and it is very easy to look at the wrong one.

I'm not sure what the ideal solution to this problem would be. There could be two different commands, such as an ng global-version and ng project-version, but this might add too much additional complexity to be worth it. Maybe the output could simply be updated to be more clear? Such as having some big red text saying "No Angular project detected at $PWD"?

主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
16 小时 35 分钟
30 天内合并 PR
176

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。