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.

InjectionToken not included in metadata

See original GitHub issue

Type of Issue

[x ] Bug Report
[ ] Feature Request

Description

I am exporting the following InjectionToken export const SX_NGX_FABRIC_DIALOG_DATA = new InjectionToken<any>('SxNgxFabricDialogData');

When I run ng-packagr, the InjectionToken is not included in the metadata.json file which resulted in the following error Error encountered resolving symbol values statically. Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler when building with the following flags ng build --prod --aot --sourcemaps --build-optimizer --named-chunks --stats-json

How To Reproduce

Add an InjectionToken in you library, run ng-packagr and try to use that injection token in the app that refereneces the library. Project can be found here: https://github.com/Abrissirba/sx-ngx-fabric

Expected Behaviour

The injection token should be included in the metadata.json

Version Information

ng-packagr: v2.0.0-rc.3
node: v8.x.y
@angular: 
rxjs: "^5.5.2",
zone.js: "^0.8.14"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
krotscheckcommented, Mar 28, 2018

A bit more insight, and a workaround from #720 as applied to my case: Apparently the issue is that - for whatever reason - the first entry point must be a direct reference to the barrel file, rather than the directory it lives in. This cascades - so if your public_api.ts is a barrel file, which itself imports from directories, the metadata won’t be constructed properly.

The workaround for this issue is: Always refer barrel files directly, don’t use directory resolution.

0reactions
github-actions[bot]commented, Sep 20, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - InjectionToken not included in metadata - - Bountysource
Type of Issue. [x ] Bug Report [ ] Feature Request. Description. I am exporting the following InjectionToken export const SX_NGX_FABRIC_DIALOG_DATA = new ......
Read more >
InjectionToken - Angular
Use an InjectionToken whenever the type you are injecting is not reified (does not have ... As mentioned above, 'root' is the default...
Read more >
Injection token not getting provided in feature modules
Tokens provided by lazy loaded modules are not accessible in the global scope; that is to say they are only available within the...
Read more >
[Angular] Provider & InjectionToken | by kelly woo - Medium
It is mostly same as class Provider at using class, but different that metadata does not create new instance, instead it uses the...
Read more >
Injection Token in Angular - TekTutorialsHub
DI Tokens. We declare the Provider in with providers metadata. This is how it looks like. 1.
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