Skip to content

Library compilation fails with Unable to write a reference to compiler cli 13.0.4 #44414

Closed
@mukundkatpatal

Description

@mukundkatpatal

Which @angular/* package(s) are the source of the bug?

compiler-cli, compiler, upgrade

Is this a regression?

Yes

Description

I have a mono repo where I have a lot of individual libraries. However, when I have upgraded from 12 to13, I am even having trouble in a single library with multiple entry points. I am trying to compile a lib with ivy enabled.
It is a simple setup where I have two modules in a single lib. Both have their own entry points using ng-package.json
I am trying to just compile this library called components And I get the below error.

ERROR: Unable to write a reference to DynamicComponentBindingDirective in C:/Source/aerdata.flare/aerdata.flare.docs/projects/components/src/lib/modules/directives/dynamic-component-binding.directive.ts from C:/Source/aerdata.flare/aerdata.flare.docs/projects/components/src/lib/modules/directives/directives.module.ts

Please provide a link to a minimal reproduction of the bug

https://github.com/mukundkatpatal/ng-13-libs

Please provide the exception or error you saw

When I do `ng build components` below is what I get.

ERROR: Unable to write a reference to DynamicComponentBindingDirective in C:/Source/aerdata.flare/aerdata.flare.docs/projects/components/src/lib/modules/directives/dynamic-component-binding.directive.ts from C:/Source/aerdata.flare/aerdata.flare.docs/projects/components/src/lib/modules/directives/directives.module.ts

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.0.4
Node: 16.13.1
Package Manager: npm 8.1.4
OS: win32 x64

Angular: 13.0.3
... animations, cdk, cdk-experimental, common, compiler
... compiler-cli, core, forms, language-service, localize
... platform-browser, platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1300.4
@angular-devkit/build-angular      13.0.4
@angular-devkit/build-ng-packagr   0.1002.0
@angular-devkit/core               13.0.4
@angular-devkit/schematics         13.0.4
@angular/cli                       13.0.4
@schematics/angular                13.0.4
ng-packagr                         13.1.1
rxjs                               6.6.7
typescript                         4.4.4

Anything else?

I am aware that the way you gather imports from the libs is reliant on rootDir, but I cant see the docs or guidance on how should these imports be coded when we have a monolith with multiple libs which we want to publish.
It would be great if the angular team demonstrates somewhere how do we structure library projects where we have multiple libraries depending on each other which need to be published. Should we use the tsConfig.paths or we should not use

I could reach till this far, but don't know how to proceed troubleshooting from here?

// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/imports/src/emitter.mjs
var ImportFlags;
(function(ImportFlags2) {
ImportFlags2[ImportFlags2["None"] = 0] = "None";
ImportFlags2[ImportFlags2["ForceNewImport"] = 1] = "ForceNewImport";
ImportFlags2[ImportFlags2["NoAliasing"] = 2] = "NoAliasing";
ImportFlags2[ImportFlags2["AllowTypeImports"] = 4] = "AllowTypeImports";
})(ImportFlags || (ImportFlags = {}));
var ReferenceEmitter = class {
constructor(strategies) {
this.strategies = strategies;
}
emit(ref, context, importFlags = ImportFlags.None) {
for (const strategy of this.strategies) {
debugger;
const emitted = strategy.emit(ref, context, importFlags);
if (emitted !== null) {
return emitted;
}
}
throw new Error(Unable to write a reference to ${nodeNameForError(ref.node)} in ${ref.node.getSourceFile().fileName} from ${context.fileName});
}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilerstate: has PR

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions