generator-angular2-library icon indicating copy to clipboard operation
generator-angular2-library copied to clipboard

Consuming your library in a local application during development, WebpackDevServer example

Open Kamilius opened this issue 8 years ago • 7 comments

Tried to preview a module with npm link on a project that uses not AngularCLI (as it is a Hybrid ng1-ng2 app), but a WebpackDevServer. Everything rebuilds on new package build.

But when page refreshes with built version of package - getting an Error: Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation., which is fixed under AngularCLI, by adding --preserve-symlinks flag to ng serve.

Exact same version works great, when built -> pushed to GitHub -> npm upgrade package_name into project.

Maybe you can advice a solution for a Webpack in this case? Would be also great to have a knowledge on Why this is happening.

Kamilius avatar Sep 21 '17 10:09 Kamilius

I have the same issue, with the same solution.

RubenVermeulen avatar Sep 21 '17 12:09 RubenVermeulen

I think be woth missed this in de docs.

" If you get Error: Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation., then try:

$ ng serve --preserve-symlinks

to make sure the consuming application searches for the peer dependencies in the application's node_modules directory."

RubenVermeulen avatar Sep 21 '17 12:09 RubenVermeulen

@RubenVermeulen you mean $ ng serve --preserve-symlinks isn't solving an issue for you?

Kamilius avatar Sep 21 '17 14:09 Kamilius

@Kamilius i find faster to link directly using the src files ( you don't have a main setup in that case so you have to import directly the file eg: ) import { MyModule } from 'my-lib/index

izifortune avatar Sep 25 '17 19:09 izifortune

In .angular-cli.json add:

"defaults": {
    "styleExt": "css",
    "component": {},
    "build": {
      "preserveSymlinks": true
    }
  }

From https://github.com/angular/angular-cli/issues/6195

raphael-volt avatar Oct 20 '17 12:10 raphael-volt

I tried preserveSymlinks and I still get:

Uncaught Error: Unexpected value 'MyModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

That is really annoying, that happens only with linked packages.

dgroh avatar Nov 15 '17 11:11 dgroh

@dgroh try removing node_modules in your linked package. This way you'll force linked package to resolve it's dependencies from consumer app

Kamilius avatar Nov 16 '17 06:11 Kamilius