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.

Cannot export "non-angular" classes with non-initialized static attributes

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

When trying to export (amongs other things) a “non-angular” class with an uninitiailized static attribute, the packaging of the library fails with the error:

 Error: C:/dev/ng-packagr-not-ng/src/app/core/my-class.ts:1:1: Error encountered in metadata generated for exported symbol 'MyClass':
 C:/dev/ng-packagr-not-ng/src/app/core/my-class.ts:2:18: Metadata collected contains an error that will be reported at runtime: Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler.

Maybe we could add something to the config to prevent metadata generation for specified files ?

How To Reproduce

Clone this repository, do yarn install (npm install should do the trick too), then run npm run build:lib. The problematic file is src/app/core/my-class.ts

Expected Behaviour

The library is build without error

Version Information

ng-packagr: 2.4.1
@angular/compiler: 5.2.9
@angular/compiler-cli: 5.2.9
rollup: 0.55.5
tsickle: 0.27.2
typescript: 2.5.3
node: 8.9.0
yarn: 1.2.1

Kind regards,

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
huang12zhengcommented, Feb 24, 2019

if you use static in your class , you need // @dynamic.

0reactions
github-actions[bot]commented, Jun 19, 2020

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

Can't access class attribute within html and angular
You will have to define a variable in you app.component.ts from type "User" and than you can access the variable: Here an example:...
Read more >
C++ Tutorial: Static Variables and Static Class Members - 2020
It cannot be accessed outside of the function/block. Class: static members exist as members of the class rather than as an instance in...
Read more >
Static initialization blocks - JavaScript - MDN Web Docs
Static initialization blocks are a special feature of a class that enable more flexible initialization of static properties than can be achieved using ......
Read more >
Typed properties in PHP 7.4 - Stitcher.io
Typed class properties have been added in PHP 7.4 and provide a major ... You cannot read from uninitialized properties, doing so will ......
Read more >
How to export class with static methods in Node.js
We know JS static keyword defines static properties and methods for a class. Static method or properties can not be called from instances...
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