How to get it working with an AoT app?
See original GitHub issueI tried https://github.com/dherges/ng-packaged but it throws an error when building as AoT.
ERROR in /Users/bc/code/Terminus/ng-packaged/src/$$_gendir/app/app.component.ngfactory.ts (11,26): Cannot find module '../../../dist/my-lib/lib.ngfactory'.
ERROR in ./src/$$_gendir/app/app.component.ngfactory.ts
Module not found: Error: Can't resolve '../../../dist/my-lib/lib.ngfactory' in '/Users/bc/code/Terminus/ng-packaged/src/$$_gendir/app'
@ ./src/$$_gendir/app/app.component.ngfactory.ts 9:0-62
@ ./src/$$_gendir/app/app.module.ngfactory.ts
@ ./src/main.ts
@ multi ./src/main.ts
I notice that the lib.ngfactory is never generated.
I then tried to test one of the sample integrations as outlined here: https://github.com/dherges/ng-packagr/blob/master/integration/README.md
But yarn sample doesn’t seem to exist. And trying to build sample_material for example, it barks about missing dependencies. When those are installed the error becomes:

🙏🏼 I would greatly appreciate any tips on this. I see that integration/consumer-ng-cli exists which seems like it should cover my use case (building a external library that is consumed by an @angular/cli app).
I seem to be very close… just missing the ngfactory file so I feel like I may just have a setting incorrect somewhere.
Thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
For the first error:
I think this is down due to
pathsmapping in tsconfig.jspn. Angular CLI generates the factory classes correctly – a library only ships the*.metadata.json, the*.ngfactory.tsare created by the app’s build – but then, because of the mappings, when compiling the apptsccannot find the auto-generated factory classes.The Angular team has quite a few issues on that: angular/angular#13008, angular/angular#13487, angular/angular#12249, angular/angular#16281, possibly more.
What does work then, is to change that
pathsmapping and copy thedistfolder of the library to the root folder of the CLI sources. Example:Then, for some reason,
tscpicks up the*.ngfactory.tsfiles from the right places. It works in another project that way, just I’d like to not put a workaround example into ng-packaged for the time being.Second, another option would be to use
yarn link. It creates a symlink fromnode_modules/@foo/barto dist-folder-of-library-containing-package-json`.In general, the whole “multi-module” thing is a bit weired, since the
integration-ng-clican and should beyarn installed in its own directory (I tried theyarn linkin there), while the other samples MUST NOT beyarn installed(they share dependencies from the root of the project).To be honest, I am working around the issue for the time being. Ideally, I’d like to see what (yarn workspaces #3294)[https://github.com/yarnpkg/yarn/issues/3294] gives to “multi-module projects” and then see later how to set-up such a “multi-module workspace” … maybe, it could look like this
Ahh yes, I could definitely do that. 🎆 Having a demo module with the lib would be great; but not a necessity.
Good call on the postbuild script… didn’t even think about that!
Thanks again for the quick responses!