Not possible to generate a correct ngfactory import for an npm package using summary files #29454
Labels
area: bazel
Issues related to the published `@angular/bazel` build rules
Milestone
Here is the scenario that Bazel users will encounter:
.metadata.json
files rather than codegen outputs (at least until a later point when the codegen is stable and we recommend that libraries publish it, maybe around v9).ngsummary.json
files, partly to avoid cascading re-builds. They cannot do codegen for npm packages since that would mean two rules have conflicting outputs, or duplicate the codengc
as a postinstall step so that npm packages contain codegen before Bazel references them. This createsngsummary.json
files frommetadata.json
files, though @alxhub is surprised that it even works to do that..metadata.json
to.ngsummary.json
files works okay for a leaf compilation.However, a downstream compilation will read from the intermediate
ngsummary.json
file and will produce undeclared symbols in the.ngfactory.js
output.For example, in angular-bazel-example
https://github.com/angular/angular-bazel-example/tree/c1f9819a9cc5f431a970a4ab6125860eef32b5a0
If we build
//src/material
we getdist/bin/src/material/material.module.ngsummary.js
which is good, but the corresponding .json output doesn't propagate the module name:
dist/bin/src/material/material.module.ngsummary.json
This means that a downstream compilation unit like
//src
will producedist/bin/src/application.module.ngfactory.js
that references theMatToolbar
symbol but never declares it, leading to runtime errors.Here's an analysis of how we get to that state:
First, within the compiler, we don't find an import location for this. We try to write the import to the ngfactory here:
angular/packages/compiler/src/aot/compiler.ts
Line 255 in cfa6e8e
which calls to the
_fileNameToModuleName
angular/packages/compiler/src/aot/compiler.ts
Line 704 in cfa6e8e
but the
importedFilePath
is not found in the summaryResolver's knownModuleName lookup table.Then we fall through to asking the host. Even if we strip off the
external/npm/node_modules
, the host cannot know the right import because the javascript file to load is in a different place from the files we read the summary data.FAQ
The text was updated successfully, but these errors were encountered: