Skip to content

"ng generate module/component" doesn't work as expected #5127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bboehm86 opened this issue Mar 1, 2017 · 10 comments
Closed

"ng generate module/component" doesn't work as expected #5127

bboehm86 opened this issue Mar 1, 2017 · 10 comments

Comments

@bboehm86
Copy link

bboehm86 commented Mar 1, 2017

Please provide us with the following information:

OS?

  • Windows 10

Versions.

@angular/cli: 1.0.0-rc.0                      
node: 7.5.0                                   
os: win32 x64                                 
@angular/animations: 4.0.0-rc.1               
@angular/common: 4.0.0-rc.1                   
@angular/compiler: 4.0.0-rc.1                 
@angular/core: 4.0.0-rc.1                     
@angular/forms: 4.0.0-rc.1                    
@angular/http: 4.0.0-rc.1                     
@angular/platform-browser: 4.0.0-rc.1         
@angular/platform-browser-dynamic: 4.0.0-rc.1 
@angular/platform-server: 4.0.0-rc.1          
@angular/router: 4.0.0-rc.1                   
@angular/cli: 1.0.0-rc.0                      
@angular/compiler-cli: 4.0.0-rc.1             

Repro steps.

  1. run ng g m my-module - [ will work as expected ]

  2. decide that you want a module and routes, so run ng g m my-module --routing

  3. get asked if you want to override the old module, hit y

  4. get sad because the routing file was not created 😢

  5. decide that you want to add a component matching the module name, so run ng g c my-module

  6. get sad again because the new component got not added to your new my-module.module.ts but to your app.module.ts 😢

  7. be happy again because the Angular CLI is such a timesaver for most parts 😄👍

The log given by the failure.


Mention any other details that might be useful.

Thanks to the team for all the effort ❤️


@RicardoVaranda
Copy link
Contributor

Hi @bboehm86 ,

I tried to repo your issue and I can confirm it happens on projects running cli RC0, I first tested on Beta.29 this issue was not present.

For your last 2 points, it sounds like it's more of a new feature request to support adding components to specific modules. The thing is that the cli is in RC now which means no new features will be added until 2.0

I'll have a look through the recent PR on module creation to see what can be causing the routing issue.

@bboehm86
Copy link
Author

bboehm86 commented Mar 1, 2017

Hey @RicardoVaranda ,

thanks for having a look. 👍

I'm not entirely sure that it is a new feature since I was under the impression that the new components will/should be added to the nearest module.
But okay, we can achieve that in this case with ng g c my-module/my-module --flat for now. Feels a bit hacky though.

@markgoho
Copy link
Contributor

markgoho commented Mar 1, 2017

I'm having this issue, too. All new components are being added not to the nearest module, but to the root app.module. This is not a new feature....but it does appear to be broken. I can confirm that @bboehm86 suggestion of my-module/my-module --flat does produce the desired outcome of generating a component and having the CLI add it to the module in that director.

After generating a new module ng g module home the command ng g component home --module=home produces the following error:

Error: EISDIR: illegal operation on a directory, read
    at Object.fs.readSync (fs.js:656:19)
    at tryReadSync (fs.js:457:20)
    at Object.fs.readFileSync (fs.js:494:19)
    at Class.afterInstall (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\@angular\cli\blueprints\component\index.js:207:34)
    at tryCatch (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:538:12)
    at invokeCallback (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:553:13)
    at publish (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:521:7)
    at flush (C:\Users\Nella\Documents\GitHub\pccRegistration\node_modules\rsvp\dist\rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

@sumitarora sumitarora self-assigned this Mar 2, 2017
@filipesilva
Copy link
Contributor

@Brocco can you weigh in?

@filipesilva
Copy link
Contributor

Partially dupe of #4614

@alorle
Copy link

alorle commented Mar 3, 2017

Same here:

$ ng --version

@angular/cli: 1.0.0-rc.1
node: 6.10.0
os: win32 x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.9

Steps:

$ ng g module back --routing

installing module
  create src\app\back\back-routing.module.ts
  create src\app\back\back.module.ts

$ ng g component back\home --module back

installing component
  create src\app\back\home\home.component.sass
  create src\app\back\home\home.component.html
  create src\app\back\home\home.component.spec.ts
  create src\app\back\home\home.component.ts
EISDIR: illegal operation on a directory, read
Error: EISDIR: illegal operation on a directory, read
    at Error (native)
    at Object.fs.readSync (fs.js:731:19)
    at tryReadSync (fs.js:486:20)
    at Object.fs.readFileSync (fs.js:534:19)
    at Class.afterInstall (C:\Users\alvaro\Desktop\testing\node_modules\@angular\cli\blueprints\component\index.js:190:34)
    at tryCatch (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:538:12)
    at invokeCallback (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:553:13)
    at publish (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:521:7)
    at flush (C:\Users\alvaro\Desktop\testing\node_modules\rsvp\dist\rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The result is the expected unless the new component is not included in the module structure. In other words, the module does not declare the new component.

@delasteve
Copy link
Contributor

@bboehm86, The issue is that by not specifying --flat the CLI thinks that it is going to create a folder and begin looking in the parent folder to that component. Part of me wants to say this is the correct functionality.

@markgoho and @AlvaroOrduna, you will need to be more specific on the file you wish to use for your module.

@markgoho: ng g component home --module=home/home.module
@AlvaroOrduna: ng g component back\home --module back\back.module

That said, I'll look into creating a PR for both of these issues. I'll let the CLI team determine what the correct functionality is.

Side note: I incorrectly thought my other PR, #5218, fixed this issue. It does not.

delasteve added a commit to delasteve/angular-cli that referenced this issue Mar 4, 2017
delasteve added a commit to delasteve/angular-cli that referenced this issue Mar 4, 2017
delasteve added a commit to delasteve/angular-cli that referenced this issue Mar 4, 2017
@Brocco
Copy link
Contributor

Brocco commented Mar 6, 2017

Closing this one in favor of tracking it via #4614

@Brocco Brocco closed this as completed Mar 6, 2017
delasteve added a commit to delasteve/angular-cli that referenced this issue Mar 6, 2017
delasteve added a commit to delasteve/angular-cli that referenced this issue Mar 8, 2017
Brocco pushed a commit that referenced this issue Mar 8, 2017
* fix(@angular/cli): fix issue with console prompt bailing early

fixes #4614

* fix(@angular/cli): fix declarable types not finding closest module

fixes #5127
asnowwolf pushed a commit to asnowwolf/angular-cli that referenced this issue Apr 12, 2017
…ar#5218)

* fix(@angular/cli): fix issue with console prompt bailing early

fixes angular#4614

* fix(@angular/cli): fix declarable types not finding closest module

fixes angular#5127
@tiagocaetano
Copy link

I have same issue , when i try to generate the component, the cmd didn't create the files and the folder, inside the project.

ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './app/cp1/cp1.component'.

ERROR in ./app.module.ts
Module not found: Error: Can't resolve './app/cp1/cp1.component' in 'C:\wamp64\www\p-page\src\app'
@ ./app.module.ts 10:0-55
@ ../main.ts
@ multi webpack-dev-server/client?http://localhost:4200 ../main.ts
webpack: Failed to compile.
webpack: Compiling...
Hash: b46038d9bcc98a16a342
Time: 2868ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {4} [initial]
chunk {1} main.bundle.js, main.bundle.js.map (main) 5.44 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.19 MB [initial]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry]

ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './src/app/cp1/cp1.component'.

ERROR in C:/wamp64/www/p-page/src/app/app.module.ts (5,30): Cannot find module './src/app/cp1/cp1.component'.

ERROR in ./app.module.ts
Module not found: Error: Can't resolve './src/app/cp1/cp1.component' in 'C:\wamp64\www\p-page\src\app'
@ ./app.module.ts 10:0-59
@ ../main.ts
@ multi webpack-dev-server/client?http://localhost:4200 ../main.ts
webpack: Failed to compile.


@angular/cli: 1.2.7
node: 6.10.2
os: win32 x64
@angular/animations: 4.3.3
@angular/common: 4.3.3
@angular/compiler: 4.3.3
@angular/core: 4.3.3
@angular/forms: 4.3.3
@angular/http: 4.3.3
@angular/platform-browser: 4.3.3
@angular/platform-browser-dynamic: 4.3.3
@angular/router: 4.3.3
@angular/cli: 1.2.7
@angular/compiler-cli: 4.3.3
@angular/language-service: 4.3.3

C:\wamp64\www\p-page\src\app>

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
How i can fix this ...

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants