Library compilation fails with `Unable to write a reference to` compiler cli 13.0.4
See original GitHub issueWhich @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}
);
}
};
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hi All,
I am still having a problem. In the below example, I am trying to build the
components
library as a package and use it in another library calledshared-lib
. So now I access the modules/components from thecomponents
library from the node_modules. But when I try to compile theshared-lib
I get the below error. What should be the right tsconfig settings? Or is it something really wrong in the code itself? The code runs in the application.✖ Compiling with Angular sources in Ivy partial compilation mode. Unable to write a reference to GridModel in C:/Source/ng13SampleApp/node_modules/components/lib/grid.model.d.ts from c:/source/ng13sampleapp/projects/shared-lib/src/lib/shared-lib.component.ngtypecheck.ts
The github URL is below.
https://github.com/mukundkatpatal/ng13SampleApp
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.