4

I want create an external module and then import it into my project.

I create a simple module ( widget.module.ts ) that have a component ( widget.component.ts ), so i generate a package.json file using npm

npm init --scope=@mylibs
# i give the name widget
# the entrypoint is widget.module.js

npm install
# it create node_module folder

npm link
# it create the link

then i create a simple app

ng new MySimpleApp

in the MySimpleApp path i link my module

npm link @mylibs/widget

but when i launch my app

ng serve

i have this error:

'WidgetModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

Vito Lipari
  • 795
  • 8
  • 35
  • Have you placed the **@NgModule** decorator in your WidgetModule? – Julius Dzidzevičius Jul 03 '17 at 13:51
  • It works exactly the same if the module was in your `src` folder. The only difference is the import paths are not relative. That means typescript should be resolving imports to your node_modules when they are explicit. – Reactgular Jul 03 '17 at 14:02
  • yes, my module have the @NgModule decorator, and in my app there is the @mylibs/widget folder under the node_module folder. How can i solve this problem? – Vito Lipari Jul 03 '17 at 14:40
  • I'm thinking this is because of an issue I read about. Angular doesn't support it well when there's a separate dependency on Angular. Basically, in your package you have a different `instance` of `NgModule` then in your main application, which causes this confusion. I'm looking for an answer to this problem myself, so no real further help there. – Bjorn 'Bjeaurn' S Dec 12 '17 at 06:44

0 Answers0