Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 module has no exported member

For a website with authentication in Angular2, I want to use a component of the authentication submodule in the main app component. However, I keep getting the following error:

app/app.component.ts(3,10): error TS2305: Module '"<dir>/app/auth/auth.module"' has no exported member 'SigninComponent'.

even after exporting SigninComponent.

The project folder structure is as shown below:

enter image description here

app/auth/auth.module.ts:

import { NgModule }       from '@angular/core'; import { CommonModule }   from '@angular/common'; import { FormsModule }    from '@angular/forms';  import { RegisterComponent }    from './components/register.component'; import { SigninComponent }    from './components/signin.component'; import { HomeComponent }    from './components/home.component';  import { AuthService } from './services/auth.service'; import { AuthHttp } from './services/auth-http';  @NgModule({   imports: [       CommonModule,       FormsModule   ],   declarations: [       RegisterComponent,       SigninComponent,       HomeComponent   ],   providers: [       AuthService,       AuthHttp   ],   exports: [       RegisterComponent,       SigninComponent,       HomeComponent   ] }) export class AuthModule {} 

app/auth/components/signin.component.ts:

import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { AuthService } from '../services/auth.service';  @Component({     selector: 'signin',     templateUrl: 'app/auth/signin.html' }) export class SigninComponent {     ... } 

app/app.component.ts:

import { Component, OnInit } from '@angular/core'; import { Router, RouterOutlet } from '@angular/router'; import { SigninComponent, RegisterComponent } from './auth/auth.module'; import { AuthHttp } from './auth/services/auth-http'; import { AuthService } from './auth/services/auth.service';  @Component({     selector: 'myapp',     templateUrl: 'app/app.html' })  export class AppComponent implements OnInit {     ... } 

app/app.module.ts:

import { NgModule }      from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule }   from '@angular/forms'; import { HttpModule }    from '@angular/http'; import { RouterModule } from '@angular/router'; import { AppRoutingModule } from './app-routing.module'; import { AuthModule } from './auth/auth.module';  import { AppComponent } from './app.component';  import { AuthService } from './auth/services/auth.service'; import { AuthHttp } from './auth/services/auth-http';  @NgModule({   declarations: [       AppComponent,       AuthService,       AuthHttp   ],   bootstrap: [ AppComponent ],   imports : [       BrowserModule,       FormsModule,       HttpModule,       AuthModule,       AppRoutingModule   ],   providers: [       AuthService,       AuthHttp   ] }) export class AppModule { } 
like image 831
user2416984 Avatar asked Dec 21 '16 14:12

user2416984


People also ask

Does ts not have default export?

The "Module has no default export" error occurs when we try to import as default from a module that doesn't have a default export. To solve the error make sure the module has a named export and wrap the import in curly braces, e.g. import {myFunction} from './myModule' .

How do I export a function in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.

What is export type in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

What is declare module in TypeScript?

The TypeScript declares module is one of the modules and keyword it is used for to surround and define the classes, interfaces; variables are also declared it will not originate with the TypeScript like that module is the set of files that contains values, classes, functions/methods, keywords, enum all these contains ...


2 Answers

Working with atom (1.21.1 ia32)... i got the same error, even though i added a reference to my pipe in the app.module.ts and in the declarations within app.module.ts

solution was to restart my node instance... stopping the website and then doing ng serve again... going to localhost:4200 worked like a charm after this restart

like image 82
Akber Iqbal Avatar answered Oct 02 '22 18:10

Akber Iqbal


You do not need the line:

import { SigninComponent, RegisterComponent } from './auth/auth.module'; 

in your app.component.ts as you already included the AuthModule in your app.module.ts. AutModule import is sufficient to use your component in the app.

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'; 
like image 40
Fjut Avatar answered Oct 02 '22 18:10

Fjut