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.

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

See original GitHub issue

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}); } };

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mukundkatpatalcommented, Dec 22, 2021

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 called shared-lib . So now I access the modules/components from the components library from the node_modules. But when I try to compile the shared-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

0reactions
angular-automatic-lock-bot[bot]commented, Feb 6, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular 13 ng build library fails (ivy partial compilation mode)
I try ng build my-lib and get the below error. ✖ Compiling with Angular sources in Ivy partial compilation mode. Transform failed with ......
Read more >
Angular Ivy: Overcome the first obstacles - DEV Community ‍ ‍
1. Unable to write a reference to {X} from {Y} ... I had a library (with using a path-alias) which exported multiple modules...
Read more >
How the Angular Compiler Works
The Angular Compiler (which we call ngc) is the tool used to compile Angular applications and libraries. ngc is built on the TypeScript ......
Read more >
How To Update Angular CLI To Latest Version
To support older RxJs imports the above command automatically installs the rxjs-compat package. If you get any error try manual installation.
Read more >
@angular-devkit/build-angular | Yarn - Package Manager
The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command...
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