Skip to content
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

Language Service. Component '...' is not included in a module and will not be available inside a template #19405

Closed
WiseBird opened this issue Sep 26, 2017 · 21 comments
Labels
area: language-service Issues related to Angular's VS Code language service type: bug/fix

Comments

@WiseBird
Copy link

WiseBird commented Sep 26, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

I have a simple component:

@Component({
               selector: 'app-home',
               templateUrl: './home.component.html'
           })
export class HomeComponent {
    title = 'Home!';
}

in tsconfig there is a mapping that points to component's folder:

    "baseUrl": ".",
    "paths": {
      "home/*": ["./src/app/home/*"]
    }

and finally, component is imported using this mapping and is added to the main module alongside with root component:

    import {HomeComponent} from 'home/home.component';

    ...
    declarations: [
        AppComponent,
        HomeComponent,
    ],
    bootstrap: [
        AppComponent,
    ],
    ...

Current behavior

Language service shows error for HomeComponent: Error:(3, 2) Angular: Component 'HomeComponent' is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration

Expected behavior

No error, component is actually imported.

Minimal reproduction of the problem with instructions

Check the repo.

Environment


Angular version: 4.3.3

Others: IDE: WebStorm 2017.2.3 EAP

@WiseBird WiseBird changed the title Component '...' is not included in a module and will not be available inside a template Language Service. Component '...' is not included in a module and will not be available inside a template Sep 26, 2017
@vicb vicb added area: language-service Issues related to Angular's VS Code language service severity2: inconvenient type: bug/fix labels Sep 26, 2017
@vpop
Copy link

vpop commented Oct 13, 2017

I ran into the same issue using WebStorm EAP. Every @Component usage was showing the error highlighted in this issue: Component X is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration. The web app would run just fine though.

Updating to the latest version of the EAP (WebStorm 2017.3 EAP, Build #WS-173.3188.31, built on October 12, 2017) solved it though.

@WiseBird
Copy link
Author

WiseBird commented Oct 26, 2017

@nadav1991 Did you checked it with my reproduction? I just checked with angular 4.4.6 and WS-173.3302.13 and it's still there. Also I personally don't think it has anything to do with WS, instead language service should be blamed.

What do you mean rewrite the @component?

@RaphiStein
Copy link

For me this problem was resolved when I moved the component directory to the same level as the module.

To illustrate, I went from:

    ├── app
             ├── shared
                         ├── components
                                        ├── my-component
                                                         └── my-component.component.ts
                         └── shared.module.ts

to this

    ├── app
             ├── shared
                          ├── my-component
                                         └── my-component.component.ts
                          └── shared.module.ts

I'm not sure why it didn't work the previous way. All the imports and paths were correct. Since it worked after de-nesting the components I'm just keeping it this way

@ruipimentel
Copy link

@RaphiStein thank you, that did work.

Anyways, I would be glad if this bug was fixed, because only small modules could bear keeping its components on the same folder.

@picosam
Copy link

picosam commented Nov 30, 2017

Actually, in my case, it still shows the error, even when I have the following folder structure and the release version of WebStorm 2017.3:

├─ app
       ├─ shared
               ├─ components
                      └── my-component.component.ts
              └── shared.module.ts

@chiefbrwnmeanie
Copy link

i am having the same errors. however, if i quit and re-open webstorm, the error goes away. i've also noticed this with random "unknown element" errors when i have installed such things as angular material. i wonder if it's a cache issue. next time i'll get it (likely later today), maybe using "invalidate caches" in the menu would do the trick...

Env details:
Angular CLI: 1.5.4
Angular: 5.0
WebStorm 2017.3 (173.3727.108)
Mac OS X : 10.13.1
WebStorm 2017.3

@picosam
Copy link

picosam commented Dec 1, 2017

I think this is related to #16382

@LinaSchad
Copy link

I just ran into that as well. Like for chiefbrwnmeanie quitting and re-opening did the job.

@MariMax
Copy link

MariMax commented Dec 26, 2017

same here

WebStorm 2017.3.1
Build #WS-173.3942.31, built on December 11, 2017
Mac OS X 10.12.6

@grigala
Copy link

grigala commented Dec 27, 2017

Same here...

Screenshot

@anodynos
Copy link

anodynos commented Jan 5, 2018

Any updates? I have the same problem with Angular 5.1.2, Webstorm 2017.3.1, Mac or Linux x64.

kyliau added a commit to kyliau/angular that referenced this issue Jan 5, 2018
This commit fixes a bug whereby the empty set of analyzed modules is
cached and subsequently produces the incorrect error 'Component ... is
not included in a module...'

PR Close angular#19405
kyliau added a commit to kyliau/angular that referenced this issue Jan 5, 2018
This commit fixes a bug whereby the empty set of analyzed modules is
cached and subsequently produces the incorrect error 'Component ... is
not included in a module...'

PR Close angular#19405
kyliau added a commit to kyliau/angular that referenced this issue Jan 6, 2018
This commit fixes a bug whereby the caches are not cleared when the
program changes. This subsequently produces the incorrect error of
'Component ... is not included in a module ...'.

PR Close angular#19405
@avbentem
Copy link

avbentem commented Jan 8, 2018

Maybe unrelated, but just in case:

  1. Having "TypeScript Language Service" enabled in WebStorm, when package.json does not refer to any language service, works just fine for me:

    image

  2. With the very same settings, also using npm install --save-dev @angular/language-service throws the following for https://github.com/angular/angular.io/blob/master/public/docs/_examples/testing/ts/src/testing/router-stubs.ts

    Error:(11, 2) ng: Directive 'RouterLinkStubDirective' is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration

    Error:(26, 2) ng: Component 'RouterOutletStubComponent' is not included in a module and will not be available inside a template. Consider adding it to a NgModule declaration

  3. Disabling the settings in WebStorm while keeping "@angular/language-service": "5.1.3" as added by option 2, also works fine.

(I don't know what I'm missing when not having that line in package.json, but I'm fine without it, so I simply keep using option 1.)

WebStorm 2017.3.2 (latest version), Angular 5.1.3 (latest version).

@Rawr421
Copy link

Rawr421 commented Jan 9, 2018

avbentem solved my problem by checking the 'recompile on changes' box in the options for Webstorm. The next time I changed a character it was recompiled and the errors went away. Thanks!

kyliau added a commit to kyliau/angular that referenced this issue Jan 10, 2018
This commit fixes a bug whereby the caches are not cleared when the
program changes. This subsequently produces the incorrect error of
'Component ... is not included in a module ...'.

PR Close angular#19405
alexeagle pushed a commit that referenced this issue Jan 12, 2018
This commit fixes a bug whereby the caches are not cleared when the
program changes. This subsequently produces the incorrect error of
'Component ... is not included in a module ...'.

PR Close #19405

PR Close #21337
@jeenn
Copy link

jeenn commented Jan 22, 2018

@Rawr421 thank you, changing a character and recompiling did the trick

@BeatriceThalo
Copy link

Using Node in VS Code, changing tsconfig.json compileOnSave: false to true solved my problem.

leo6104 pushed a commit to leo6104/angular that referenced this issue Mar 25, 2018
This commit fixes a bug whereby the caches are not cleared when the
program changes. This subsequently produces the incorrect error of
'Component ... is not included in a module ...'.

PR Close angular#19405

PR Close angular#21337
@kevinbeal
Copy link

Using that same menu @avbentem shows and toggling the Angular Language Service (applying changes in between) resolves the issue for the editor.

@Sbitneva
Copy link

Try to close - open IDEA
it help in my case :)

@schurik
Copy link

schurik commented Jan 14, 2019

I get the same error as already mentioned.
Angular 7.2
IntelliJ IDEA 2018.3.3 (Ultimate Edition) Build #IU-183.5153.38, built on January 9, 2019
macOS 10.14.2.

I tried several solutions. close IDEA, enable the 'Recompile on change' option, tsconfig.json compileOnSave: true, invalidate the cache, ... but nothing helped.
Is there a fix for this error?

@Sbitneva
Copy link

Sbitneva commented Jan 17, 2019 via email

@moorzaa
Copy link

moorzaa commented Jan 30, 2019

I get the same error as already mentioned.
Angular 7.2
IntelliJ IDEA 2018.3.3 (Ultimate Edition) Build #IU-183.5153.38, built on January 9, 2019
macOS 10.14.2.

I tried several solutions. close IDEA, enable the 'Recompile on change' option, tsconfig.json compileOnSave: true, invalidate the cache, ... but nothing helped.
Is there a fix for this error?

uncheck angular language service

@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 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: language-service Issues related to Angular's VS Code language service type: bug/fix
Projects
None yet
Development

No branches or pull requests