Independently compiled Typescript loses Annotations (Angular 2: No Directive annotation found on <Component>)
I'm submitting a bug report
Webpack version: 1.13.1
Please tell us about your environment: Windows
Current behavior: Consuming a webpack application from another webpack application does not make typescript annotation data available to the consuming application.
Expected/desired behavior:
The modules from the library are being bundled and exported, and the consumer is able to import them beautifully. However, annotation data is missing, as pointed out by Angular 2's error No Directive annotation found on <Component>
- See https://github.com/sky-coding/angular-2-webpack-library for a concise demo of the problem. A branch is running typescript 2.x, with the same problem.
- Another user has tracked the issue down to an internal webpack mechanism https://groups.google.com/forum/#!topic/angular/KDuV6Qvke7Y
- I've tried removing webpack from the library, simply using
tscto compile a single component/file, and then loading that into the webpack consumer. This results in the exact same behavior, leading me to believe that the consuming webpack is at fault.. - What is the motivation / use case for changing the behavior? Most third-party Angular 2 libraries are bundled using SystemJs or other tools , which do not have this issue. I love webpack and think it is perfect for this scenario, and I'm hopeful that more third-party libraries will adopt webpack when this issue is addressed.
- Browser: [all]
- Language: [ TypeScript 1.X | TypeScript 2.X ]
Two copies of @angular/core are included in your bundle. Each app has it's own node_modules with a separate copy of angular.
You can enforce using a single copy with
resolve.alias: { '@angular/core': require.resolve('@angular/core') }.
@sokra Thanks for the help, I investigated and found that my library's external dependencies are correctly excluded when bundling, however, the consumer app resolves the library's external dependencies locally (and node_modules is present in the library's directory when using npm link) meaning that the library is indeed using its own version of angular.
I added resolve.alias entries on the consumer for all of my library's dependencies (which fails to compile) but this seems like the wrong approach, does my consumer really need to list every single external dependency of its AMD/UMD libraries?