angular / angular-cli

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

ng new with older @angular/cli version generates an Angular 10 project #18731

Closed Waterstraal closed 4 years ago

Waterstraal commented 4 years ago

🐞 Bug report

Command (mark with an x)

Is this a regression?

Yes, it used to work in an older version. I'm not sure when I last ran this command, but my best guess is around Angular 6.

Description

Installing a new Angular project using npx and specifying an older @angular/cli@9 version generates an Angular 10 project.

πŸ”¬ Minimal Reproduction

Run npx -p @angular/cli@9 ng new ng9-app --interactive=false

Open package.json and see that it installed Angular 10 dependencies:

  "dependencies": {
    "@angular/animations": "~10.1.0",
    "@angular/common": "~10.1.0",
    "@angular/compiler": "~10.1.0",
    "@angular/core": "~10.1.0",
    "@angular/forms": "~10.1.0",
    "@angular/platform-browser": "~10.1.0",
    "@angular/platform-browser-dynamic": "~10.1.0",
    "@angular/router": "~10.1.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },

I would expect to see dependencies on version 9.x

🌍 Your Environment

Windows 10 Node.js 12.4.0

alan-agius4 commented 4 years ago

Can you try npx @angular/cli@9 new ng9-app --interactive=false

Waterstraal commented 4 years ago

same result:

  "dependencies": {
    "@angular/animations": "~10.1.0",
    "@angular/common": "~10.1.0",
    "@angular/compiler": "~10.1.0",
    "@angular/core": "~10.1.0",
    "@angular/forms": "~10.1.0",
    "@angular/platform-browser": "~10.1.0",
    "@angular/platform-browser-dynamic": "~10.1.0",
    "@angular/router": "~10.1.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
clydin commented 4 years ago

The -p option will cause the version specifier to not be used. However, the command suggested above (npx @angular/cli@9 new ng9-app --interactive=false) should work. If this does not, then one likely cause is that a version of the CLI is installed in the directory hierarchy above the current directory. Could you check if there is an installed instance of the CLI (or potentially a node_modules directory in or above the current directory)?

Waterstraal commented 4 years ago

Thanks for the information!

I found a node_modules directory in a direct parent. When I removed it and then ran npx @angular/cli@9 new ng9-app --interactive=false it installed the expected v9

Regardless, I would expect v9 to be installed with above command wherever I run it, or is this logic flawed somehow?

alan-agius4 commented 4 years ago

What's happening here is that at the moment the Angular CLI initialization code will always defer to the "local" installed version in case there is one.

When you use npx you are essentially install a temporary global version of @angular/cli, but since you have another "local" @angular/cli in the directory hierarchy above the current directory the command will be deferred to the latter version.

angular-automatic-lock-bot[bot] commented 4 years ago

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.