angular / angular-cli

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

Using externalSchematic to run an ng add doesn't install expected modules #15250

Closed ttrichar closed 5 years ago

ttrichar commented 5 years ago

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ x ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No

Description

I'm trying to use externalSchematic to run an ng add for ng-momentum (https://github.com/BottleRocketStudios/ng-momentum).

This is the repository where my code currently resides: (https://github.com/lowcodeunit-devkit/ng-lcu/blob/master/src/momentum/index.ts)

I have been able to create an angular project using ng new mynewproject, and can successfully run ng add ng-momentum outside of the CLI. However, when I try to run an external schematic, I get an error that says the module "ng-momentum" can't be found. I would expect the normal behavior to add the necessary modules, like it does when ng add ng-momentum is run normally. Below is the external schematic chain:

return chain([
   externalSchematic('ng-momentum', 'scaffold', {
    project: options.project,
  })

I'm using 'scaffold', in accordance with the ng-momentum documentation. (https://github.com/BottleRocketStudios/ng-momentum/blob/master/src/collection.json)

πŸ”¬ Minimal Reproduction

1) Install our CLI (npm i @lcu/cli -g) 2) In an empty folder, run command "lcu init". Use scope = "@scope" and workspace ="workspace" 3) After the init command, run "lcu proj newProject" in the same folder. Choose "App". Choose "Momentum"

Expected behavior: The externalSchematic method will run "ng add ng-momentum", and create the app as expected

Actual behavior: App is not created, the module "ng-momentum" is unable to be found (see error below)

πŸ”₯ Exception or Error


"Could not find module "ng-momentum" from "C:\\whatever\\folder\\you\\chose"". 

🌍 Your Environment


Angular CLI: 8.1.3
Node: 11.10.0
OS: win32 x64
Angular: 8.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

@angular-devkit/architect        0.801.3
@angular-devkit/core             8.1.3
@angular-devkit/schematics       8.1.3
@angular-devkit/schematics-cli   0.801.3
@schematics/angular              8.1.3
@schematics/schematics           0.801.2
@schematics/update               0.801.3
rxjs                             6.4.0
typescript                       3.4.5

**Anything else relevant?**
Please let me know if you need any additional information, or if this should be posted into a different repo. Thank you so much!            
clydin commented 5 years ago

This is expected and intended behavior.

externalSchematic executes a schematic from a different schematic collection than the currently executing schematic. The referenced schematic collection needs to exist. It does not perform any package installation; that is outside the scope of the rule.

An ng-add schematic is also no different than any other schematic other than that it is executed by the ng add command after the ng add command locates and potentially installs the requested package and its dependencies (if any).

angular-automatic-lock-bot[bot] commented 5 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.