Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Module has no exported member

Here I am again, hoping to find a quick solution to this:

Link <- Click on this link to see the folder structure

//main.ts
import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './home.main';
import {InputComponent} from './home.controller';
import {enableProdMode} from 'angular2/core';


bootstrap(InputComponent);
bootstrap(AppComponent);

This is my main.ts file where I import the AppComponent from home main, now the home.main looks like this:

import {Component} from 'angular2/core';

    @Component({
    selector:'home',
    templateUrl:'/index/index.ejs'
    })

    export class InputComponent {
      name = 'test';
     }

However, when I run this, I get: error TS2305: Module '"controllers/home/home.main"' has no exported member 'AppComponent'. ( Same goes for home.controller ).

Thank you, Alex S.

like image 504
Okei Avatar asked Apr 11 '16 18:04

Okei


People also ask

Why am I getting multiple versions of angular in node_modules?

@grosch That may happen if there's multiple versions of Angular present in node_modules, i.e. some dependency has a direct dependency (instead of a peer dependency) on an older version of Angular. You can figure this out using npm ls @angular/core. Sorry, something went wrong. @JoostK Thank you so much! Sorry, something went wrong.

Why is there no exported member in my signin component?

The error that you get is a TypeScript error, not a Angular one, and it is correct in stating that there is no exported member, as it searches for a valid EC6 syntax for export, not angular module export. This line would thus work in your app.component.ts: import { SigninComponent } from './auth/components/signin.component';

Is this a regression when running ng build/serve after updating angular 9?

Is this a regression? Running ng build/serve after updating to angular 9 produces a number of errors, all surrounding an export in angular/core

Is Ivy compatible with angular 2?

This is not compatible, and it's not meant to be. As of right now, libraries should be published with Ivy disabled, otherwise their compatibility with Angular versions, both older and upcoming versions is highly crippled. The reason is that Ivy's generated code (its instruction set) is not set in stone yet, so changes are to be expected.


Video Answer


3 Answers

I had this issue even when I had correctly exported the class on my other file. Rebooting my machine fixed it.

like image 120
Bruno Peres Avatar answered Sep 21 '22 16:09

Bruno Peres


If you see this error in any @angular modules like router, core, then make sure it is because of the version mismatch of the libraries. Generally all your @angular modules should be of the same version except router.

for Ex:

    "@angular/common": "2.2.3",
    "@angular/compiler": "2.2.3",
    "@angular/core": "2.2.3",
    "@angular/platform-browser": "2.2.3",
    "@angular/platform-browser-dynamic": "2.2.3",
    "@angular/router": "^3.3.0" <= Version mismatch***

the following combination throws following error

has no exported member

I changed the router version to

"@angular/router": "^3.0.0"

The error is resolved.

So, until everything is stable stick with your working combination.

like image 29
Ignatius Andrew Avatar answered Sep 21 '22 16:09

Ignatius Andrew


You should have something like that in your home.main module:

@Component({
  (...)
})
export class AppComponent {
}
like image 23
Thierry Templier Avatar answered Sep 21 '22 16:09

Thierry Templier