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

Problem with @NgModule Decorator while importing Modules from other project #196

Open
tkarzewski opened this issue Feb 24, 2017 · 3 comments

Comments

@tkarzewski
Copy link

Hey guys! Pretty cool stuff you built there! I like :-)

Unfortunately I am facing problems when I want to develop and import several projects and got this error: bundle() requires a decorated NgModule as its first argument.
For example I have a project my-shared-app with a ListComponent. I want to use this ListComponent in my project my-main-app.

my-main-app -> my-shared-app

For local development I use npm link to link the repos, but for example purpose I created those repos:

In my-main-app I adjusted following files

vendor.js

import 'my-shared-app';

app.module.ts

import { NgModule } from 'ng-metadata/core';
import { AppComponent } from './app.component';
import { MySharedAppModule } from 'my-shared-app';

@NgModule( {
  imports: [
    MySharedAppModule
  ],
  declarations: [
    AppComponent
  ]
} )
export class MyMainAppModule {
}

app.component.js

import { Component } from 'ng-metadata/core';

@Component({
  selector: 'np-app',
  template: `
    <h1>Main Module</h1>
    <np-list [entries]="$ctrl.entries"></np-list>
  `
})
export class AppComponent {

  entries = [
    { id: 1, label: 'Entry 1' },
    { id: 2, label: 'Entry 2' },
    { id: 3, label: 'Entry 3' },
    { id: 4, label: 'Entry 4' },
  ]

}

Do you see, what I'm doing wrong? Any suggestions?
Thx for help! :-)

@DaSchTour
Copy link

Well I don't see anything wrong in the first place.

But the import of my-shared-app doesn't fell good for me. This kind of imports is handled very differently through different module loaders and module systems. It's always better to really import something for this module and execute than to depend on execution by import.

import 'my-shared-app';

@Nosfistis
Copy link

The problem is in the module check:

return annotation instanceof NgModuleMetadata

Your compiled module metadata won't have the same instance of NgModuleMetadata.

@Nosfistis
Copy link

It is possible to work around this by exporting the module name:

@NgModule()
class CommonModule{
}

const CommonModuleName = bundle(CommonModule).name;

export { CommonModuleName as CommonModule };

This way, module consumers work as intended without having to bundle the module themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants