question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component library local development with npm link error: "Please add a @NgModule annotation"

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.6 node: 6.9.5 os: win32 x64 @angular/common: 4.1.3 @angular/compiler: 4.1.3 @angular/core: 4.1.3 @angular/forms: 4.1.3 @angular/http: 4.1.3 @angular/platform-browser: 4.1.3 @angular/platform-browser-dynamic: 4.1.3 @angular/router: 4.1.3 @angular/cli: 1.0.6 @angular/compiler-cli: 4.1.3

Repro steps.

  1. Create an empty angular-cli project
  2. Create a new Angular component library with at least one module and one component.
  3. Build the component library with ngc -p ./src/tsconfig.lib.json
  4. Register the component library running npm link at the /dist folder of the library.
  5. From the angular-cli project link to the component library: npm link component-library-package-name
  6. Use the component library (import a module and use a component).
  7. Start the angular-cli project with ng serve.
  8. It compiles but it will fail in the browser with the following error: Unexpected value 'MyModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

The log given by the failure.

Chrome error log:

compiler.es5.js:1540 Uncaught Error: Unexpected value 'MyModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
    at syntaxError (http://localhost:4200/vendor.bundle.js:29720:34)
    at http://localhost:4200/vendor.bundle.js:42674:44
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:42657:49)
    at JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:53810:66)
    at JitCompiler._compileModuleAndComponents (http://localhost:4200/vendor.bundle.js:53769:52)
    at JitCompiler.compileModuleAsync (http://localhost:4200/vendor.bundle.js:53731:23)
    at PlatformRef_._bootstrapModuleWithZone (http://localhost:4200/vendor.bundle.js:5731:25)
    at PlatformRef_.bootstrapModule (http://localhost:4200/vendor.bundle.js:5717:21)
    at Object.122 (http://localhost:4200/main.bundle.js:303:124)

Desired functionality.

Mention any other details that might be useful.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
clydincommented, May 30, 2017

Your component library setup looks fine. The app needs some slight adjustment to ensure that the application’s Angular libraries are used and not the library’s development dependencies. This change will essentially mimic the standard behavior of the Angular peer dependencies in the context of a linked library. In src/tsconfig.app.json, add the paths setting as follows:

{
  "compilerOptions": {
    // ...
    "paths": {
      "@angular/*": [
        "../node_modules/@angular/*"
      ]
    }
  }
}
6reactions
DooMMasteRcommented, Sep 26, 2017

I have the same issue, but only in development, the result of the production compile run works just fine. "paths": { "@angular/*": ["../node_modules/@angular/*"] } is already set up in my tsconfig.app.json but in development I still get an @NgModule annotation error.

@angular/cli: 1.4.3
node: 6.11.3
os: linux x64
@angular/animations: 4.4.3
@angular/common: 4.4.3
@angular/compiler: 4.4.3
@angular/core: 4.4.3
@angular/forms: 4.4.3
@angular/http: 4.4.3
@angular/platform-browser: 4.4.3
@angular/platform-browser-dynamic: 4.4.3
@angular/router: 4.4.3
@angular/cli: 1.4.3
@angular/compiler-cli: 4.4.3
@ngtools/webpack: 1.7.1
typescript: 2.3.4
Read more comments on GitHub >

github_iconTop Results From Across the Web

Please add a @NgModule annotation but I cannot figure why
I have a Node/Angular app which works locally in a Docker instance. For deployment to a Google VM, ...
Read more >
Create an Angular 14 Library, use it locally when developing ...
We have created an Angular project and generated a library ngx-everything-uppercase . We linked the package using npm link so we can install ......
Read more >
Ihg-ng-common-pages NPM | npm.io
This ihg-library-seed is used to create a standalone Angular library in seconds. ... If you want to test the common components while you...
Read more >
NgModule FAQ - Angular
What classes should I add to the declarations array?link. Add declarable classes —components, directives, and pipes— to a declarations list. Declare these ...
Read more >
generator-angular2-library - UNPKG
The CDN for generator-angular2-library. ... NPM version][npm-image]][npm-url] [![ ... Please add a @NgModule annotation.`, then try:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found