Apps cannot build with AOT if a dependent library was built with barrels #23713
This issue describes mysterious build failures for apps that depend on an npm-installed library that was built with barrels.
The problem lies somewhere in the interaction among barrels, AOT, and
Workaround: Do not use barrels in your library. Always and everywhere make direct references to the source files.
I'm submitting a...
That library was built with barrels.
Specifically, the top-level
The library author (me) was able to build that library for production without any warnings or errors.
But occasionally you'd get weird errors when you
Note the reference in the error to
The constant was initialized ... on line 16 in
Shuffling the order of exports in the top level
These are all clues that you are using barrels and AOT + ngPackagr` do not like barrels.
I think we should be able to use barrels.
AOT + ngPackagr should be able to determine the proper dependency order as is possible with JIT compilation.
Minimal reproduction of the problem with instructions
There is no easy way to reproduce this bad behavior because barrels often appear to work. The problem likely arises when a library's sub-files refer to files that are exported in other barrels (even when those references are direct to the dependent files, by-passing barrels).
You can see the horror story play-out in the
This repo has both a library (
To experience the problem:
You can build with AOT if you remove the following providers from
This succeeds because these providers reference the library's
A dev build (e.g,
If you now move forward to Beta 13 where barrels are eliminated, all of these problems go away and you can build the sample app with
What is the motivation / use case for changing the behavior?
Barrels nicely encapsulate and minimize low-level details of a library's internal folder structure.
I do not know if it is still a problem in v.6. I don't have the time to find out.
For Tooling issues: irrelevant
The text was updated successfully, but these errors were encountered:
Feel free to close this issue if we do not have time or the intention of fixing it.
I've entered it here primarily so that other library builders (a) can understand why consumers of their libraries are getting strange errors when they build their apps for production and (b) solve that problem relatively quickly by eliminating barrels from their libraries.
Relevant issue in ng-packagr:
Basically the metadata files are exported without the actual metadata because it doesn't know where to find the correct file to generate the metadata from. Here is a metadata file generated from a large library that uses barrels (with angular cli orchestrating ng-packagr):
Most of these issues prop up in AOT because AOT depends on these metadata files. As shown below with
I opened my PR for this before 6 left beta, in the hope of getting it included (and possibly backported to 5.x). However, the PR has been completely ignored for months despite numerous requests for review / comment. I can only assume the team doesn't view this as a high priority issue.
This issue has been automatically locked due to inactivity.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.