angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng generate component mymodule/mycomp fails when project root set deep

Open Red-3 opened this issue 9 years ago • 7 comments

Versions

Angular CLI: 1.5.2
Node: 8.2.1
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router, tsc-wrapped
@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.2
@angular/flex-layout: 2.0.0-beta.9
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.2
@schematics/angular: 0.1.7
typescript: 2.3.4
webpack: 3.8.1

Repro steps

The root of the @angular project in .angular-cli.json is src/main/webapp

  • Step 1 - Navigate to root folder of project
  • Step 2 - ng generate component mymodule/mycomp
  • Step 3 - ng generate component mymodule/mycomp --skip-import

Observed behavior

Step 2

Error: Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.
Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.

Step 3 Component is created in wrong directory. Full path of component is created in root/app, not at root/app (i.e. path is doubled - see below)

src/main/webapp/src/main/webapp/app/mymodule/mycomp.component.scss

Desired behavior

Component created in the correct location and imported into the project module.

Mention any other details that might be useful (optional)

  • I created a new component a couple of weeks ago, but since then I have upgraded several components, including @angular/core, @angular/material and @angular/flex-layout
  • (Project was originally created with JHipster - Java/SpringBoot backend.)
  • To troubleshoot, I created a new project with ng new myproj --source-dir src/main/webapp and it created the component OK. But this project is too complex to create afresh and port code over.
  • BTW - --source-dir option is not documented

FAO: @hansl

Red-3 avatar Nov 27 '17 23:11 Red-3

I had a similar issue in a jHipster generated project but I upgraded Angular CLI from 1.6.0 version to 1.6.1 and it seems to be working fine now.

Version 1.6.0

$ ng generate component mymodule/mycomp --skip-import -d
Your global Angular CLI version (1.6.1) is greater than your local
version (1.6.0). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false".
  create src/main/webapp/src/main/webapp/app/mymodule/mycomp/mycomp.component.html (25 bytes)
  create src/main/webapp/src/main/webapp/app/mymodule/mycomp/mycomp.component.ts (242 bytes)

NOTE: Run with "dry run" no changes were made.

Version 1.6.1

$ ng generate component mymodule/mycomp --skip-import -d
  create src/main/webapp/app/mymodule/mycomp/mycomp.component.html (25 bytes)
  create src/main/webapp/app/mymodule/mycomp/mycomp.component.ts (242 bytes)

NOTE: Run with "dry run" no changes were made.

Can you take a look too, @Red-3 ?

jiniguez avatar Dec 15 '17 13:12 jiniguez

I'm now on version 1.6.2, still no joy...

$ ng generate component signup/newcomponent --skip-import -d
input.mergeMap is not a function
TypeError: input.mergeMap is not a function
    at Object.callRule (/home/abiggs/git/wonderville/node_modules/@angular-devkit/schematics/src/rules/call.js:78:18)
    at SchematicImpl.call (/home/abiggs/git/wonderville/node_modules/@angular-devkit/schematics/src/engine/schematic.js:35:23)
    at Promise (/home/abiggs/git/wonderville/node_modules/@angular/cli/tasks/schematic-run.js:73:23)
    at Promise (<anonymous>)
    at Class.run (/home/abiggs/git/wonderville/node_modules/@angular/cli/tasks/schematic-run.js:72:16)
    at Class.run (/home/abiggs/git/wonderville/node_modules/@angular/cli/commands/generate.js:161:33)
    at resolve (/home/abiggs/git/wonderville/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
    at Promise (<anonymous>)
    at Class.validateAndRun (/home/abiggs/git/wonderville/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
    at Promise.resolve.then.then (/home/abiggs/git/wonderville/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:140:24)

Red-3 avatar Jan 02 '18 22:01 Red-3

Based upon my findings input.mergeMap is not a function is a result of different versions of rxjs being installed. This will be resolved by updating both the CLI and devkit repos to use "lettable" operators.

PRs: CLI: #8976 devkit: angular/devkit#345

Brocco avatar Jan 08 '18 16:01 Brocco

if You are using Angular 6 then change your current directory to /src/app/ then use ng g c new-component. I think the problem will be resolved, It works for me.

ved1995 avatar Jun 10 '18 06:06 ved1995

if "ng" is serving the project ..you can probably get this error also....i canceled ng serve in terminal . and it worked

macsompo avatar Jul 10 '18 11:07 macsompo

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.

alan-agius4 avatar Oct 01 '18 07:10 alan-agius4

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.