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.

How to get it working with an AoT app?

See original GitHub issue

I 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:

screen shot 2017-06-07 at 10 36 41 am


🙏🏼 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:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dhergescommented, Jun 7, 2017

For the first error:

I think this is down due to paths mapping in tsconfig.jspn. Angular CLI generates the factory classes correctly – a library only ships the *.metadata.json, the *.ngfactory.ts are created by the app’s build – but then, because of the mappings, when compiling the app tsc cannot 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 paths mapping and copy the dist folder of the library to the root folder of the CLI sources. Example:

|- .angular-cli.json
|- src
    |- app
        |- app.module.ts
    |- @foo
        |- bar

Then, for some reason, tsc picks up the *.ngfactory.ts files 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 from node_modules/@foo/bar to dist-folder-of-library-containing-package-json`.


In general, the whole “multi-module” thing is a bit weired, since the integration-ng-cli can and should be yarn installed in its own directory (I tried the yarn link in there), while the other samples MUST NOT be yarn 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

|- demo
   |- src
       |- app.module.ts
   |- .angular.cli.json
   |- package.json
|- packages
    |- lib-one
        |- package.json
        |- ng-package.json
    |- lib-two
        |- package.json
        |- ng-package.json
    |- ..
|- node_modules    # shared (!) dependencies at top-level, across all "multi-modules"
    |- @lib
         |- one # symlink to dist folder for `lib-one`
         |- two # symlink to dist folder for `lib-two`
1reaction
benjamincharitycommented, Jun 7, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable and run AOT compilation
To verify that your application is actually running in AOT, please open the browser developer tools (F12), go to the Network tab, force...
Read more >
Native AOT deployment overview - .NET
Publishing your app as native AOT produces an app that is self-contained and that has been ahead-of-time (AOT) compiled to native code. Native ......
Read more >
Angular: Writing AoT-friendly applications | by David
To demonstrate and understand how Ahead-of-Time compilation works, we need to add some features to the application. Checkout the Git tag baseline or...
Read more >
Always On Time (AOT.plus) Integrations
Zapier lets you connect Always On Time (AOT.plus) with thousands of the most popular apps, so you can automate your work and have...
Read more >
Attack On Titan VR: By Slavka Quest Port
Sign up to SideQuest to get updates for your favourite apps, as well as support the apps you like with reviews, posts and...
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