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

Unexpected value 'Frame1Component' imported by the module 'MaterialAppModule'

Open joshterrill opened this issue 10 years ago • 6 comments

OS: Mac 10.11.6 El Capitan Angular CLI Version: 1.0.0-beta.11-webpack.8

I started with this a fork of this project: https://github.com/jelbourn/material2-app/ then upgraded to a newer version of angular-cli because it was telling me I had to in the command line.

I've got a bunch of login/register/forgot password/reset password components that I have in a seperate NPM module from my own app. And then I've got my outer frame set inside app.component.html. Here is my module definition:

import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MaterialModule } from '@angular/material';
import { FormsModule } from '@angular/forms';
import { ModalModule } from 'angular2-modal';
import { BootstrapModalModule } from 'angular2-modal/plugins/bootstrap';
import { routing, appRoutingProviders }  from './app.routing';
import { AppComponent } from './app.component';
import { HomeComponent} from './home/home.component';
import { LoginComponent, RegisterComponent, ForgotPasswordComponent, ResetPasswordComponent } from 'cws/auth';


@NgModule({
  imports: [
    BrowserModule,
    MaterialModule.forRoot(),
    FormsModule,
    ModalModule.forRoot(),
    BootstrapModalModule,
    routing
  ],
  declarations: [AppComponent, HomeComponent, LoginComponent, RegisterComponent, ForgotPasswordComponent, ResetPasswordComponent],
  entryComponents: [AppComponent],
  providers: [appRoutingProviders]
})
export class MaterialAppModule {
  constructor(public _appRef: ApplicationRef) { }

  ngDoBootstrap() {
    this._appRef.bootstrap(AppComponent);
  }
}

So the frameset is in AppComponent and then all my pages are being brough in via import { LoginComponent, RegisterComponent, ForgotPasswordComponent, ResetPasswordComponent } from 'cws/auth'; and import { HomeComponent} from './home/home.component';

This works just fine. However, what I would like to do, is take my frameset component (which right now is app.component.ts and app.component.html and app.component.css and put that into it's own node module as well, so then in my app.component.html I would just be able to put <frame1></frame1> and have it load the frameset that is defined in the module. So here's what my app.module.ts looks like with that:

import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MaterialModule } from '@angular/material';
import { FormsModule } from '@angular/forms';
import { ModalModule } from 'angular2-modal';
import { BootstrapModalModule } from 'angular2-modal/plugins/bootstrap';
import { routing, appRoutingProviders }  from './app.routing';
import { AppComponent } from './app.component';
import { HomeComponent} from './home/home.component';
import { LoginComponent, RegisterComponent, ForgotPasswordComponent, ResetPasswordComponent } from 'cws/auth';
import { Frame1Component } from 'cws/frames/frame1';


@NgModule({
  imports: [
    BrowserModule,
    MaterialModule.forRoot(),
    FormsModule,
    ModalModule.forRoot(),
    BootstrapModalModule,
    routing,
    Frame1Component
  ],
  declarations: [AppComponent, HomeComponent, LoginComponent, RegisterComponent, ForgotPasswordComponent, ResetPasswordComponent],
  entryComponents: [AppComponent],
  providers: [appRoutingProviders]
})
export class MaterialAppModule {
  constructor(public _appRef: ApplicationRef) { }

  ngDoBootstrap() {
    this._appRef.bootstrap(AppComponent);
  }
}

And inside my app.component.ts:

import {Component, OnInit} from '@angular/core';
import { GetAppVersion } from 'app-version';

@Component({
  selector: 'app',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
export class AppComponent implements OnInit {

  constructor() { }

  ngOnInit() { 
    console.log("Current app version: " + GetAppVersion); 
  }

}

And inside my app.component.html:

<frame1></frame1>

And here's what's inside my cws/frames/frame1 component:

import {Component, OnInit} from '@angular/core';

@Component({
  selector: 'frame1',
  templateUrl: 'frame1.component.html',
  styleUrls: ['frame1.component.css']
})
export class Frame1Component implements OnInit {

  constructor() { }

  ngOnInit() { }

}

So what I expect to be able to happen is that my app continues to just load app.component.ts, but the HTML would have access to the cws/frames/frame1 component, so that when I use <frame1></frame1> it would inject the html and css that are defined in the component, so in this case it would be frame1.component.html and frame1.component.css.

But I'm getting

metadata_resolver.js:227Uncaught Error: Unexpected value 'Frame1Component' imported by the module 'MaterialAppModule'

Edit: I've also tried just importing the Frame1Component on the app.component.ts file itself, and then using it as a directive. But it says

Argument of type '{ selector: string; template: any; styles: any[]; directives: typeof Frame1Component[]; }' is not assignable to parameter of type 'Component'.
  Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.```

I've also tried putting it in the declarations.

joshterrill avatar Sep 29 '16 00:09 joshterrill

nice title name, so big

dolanmiu avatar Sep 29 '16 00:09 dolanmiu

Sorry, I thought I cleared that out. I just discovered something interesting. I moved everything from my node_modules/cws/frames/frame1 folder into a src/app/cws folder and did my import like this: import {Frame1Component} from './cws' and then just put Frame1Component in the declarations section of @ngImport and it works fine... so what about having that in node modules does it not like?

joshterrill avatar Sep 29 '16 01:09 joshterrill

The problem isn't having it in the node_modules folder. The problem is that you're putting a component in the imports section, which is only for NgModules. You need to put components in the declarations section.

isaacplmann avatar Sep 30 '16 16:09 isaacplmann

@isaacplmann I have removed it from the imports section and put it in declarations, and I still get Unexpected value 'Frame1Component' declared by the module 'AppModule'

joshterrill avatar Sep 30 '16 21:09 joshterrill

@joshterrill did you sort it out? If so, what caused this issue? I'm experiencing similar issue and looking for potential solution.

tomaszczechowski avatar Nov 28 '16 10:11 tomaszczechowski

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.