ng-packagr: "Cannot create property 'modifierFlagsCache'" when using string-based enums
First of all: I’m not sure if this is an issue with ng-packagr or maybe tsickle or even typescript itself. However, I didn’t know how to reproduce this issue without ng-packagr, so I thought it would be best to start here. Feel free to point me in the right direction.
Type of Issue
[x] Bug Report
[ ] Feature Request
Description
Whenever I use a string-based enum (available since TypeScript 2.4) in my project, the build process fails with this error message:
> ng-packagr -p ng-package.json
Building Angular library
Generating bundle for mfc-issue
BUILD ERROR
Cannot create property 'modifierFlagsCache' on string 'some string'
TypeError: Cannot create property 'modifierFlagsCache' on string 'some string'
at Object.getModifierFlags (C:\Users\mal\Projekte\mfc-issue\node_modules\typescript\lib\typescript.js:9685:33)
at Object.getCombinedModifierFlags (C:\Users\mal\Projekte\mfc-issue\node_modules\typescript\lib\typescript.js:10388:24)
at hasModifierFlag (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\tsickle.js:72:16)
at Annotator.maybeProcess (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\tsickle.js:538:13)
at Annotator.Rewriter.visit (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\rewriter.js:52:19)
at Annotator.maybeProcessEnum (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\tsickle.js:1188:22)
at Annotator.maybeProcess (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\tsickle.js:676:29)
at Annotator.Rewriter.visit (C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\rewriter.js:52:19)
at C:\Users\mal\Projekte\mfc-issue\node_modules\tsickle\build\src\rewriter.js:84:19
at visitNodes (C:\Users\mal\Projekte\mfc-issue\node_modules\typescript\lib\typescript.js:11911:30)
How To Reproduce
Put a string-based enum in your project:
export enum MyEnum {
StrVal = 'some string'
}
I created a simple project with for reproduction: https://github.com/luchsamapparat/mfc-issue
Expected Behaviour
no error 😃
Version Information
ng-packagr: v1.5.0-rc.0
node: v8.0.0
typescript: 2.5.3
@angular: n/a
rxjs: n/a
zone.js: n/a
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 23 (12 by maintainers)
I have the same problem and it’s worth to know that setting strings on
Enumare available only since TypeScript version2.4andng-packagris set to~2.3.3inpackage.json. However, updating TypeScript to latest still throws the error on build.After some googling, there seem to be 2 options available to bypass this issue (as shown in this SO question). 1- Change
enumto aclassand addstaticin front of eachenumproperty2- Use
enumas usual but simply add<any>in front of eachenumpropertyI decided to use the 2nd option since it remains as an Enum, even though it’s a little bit hacky. This is still a hack, so if someone finds the correct way to fix it, then please advise.
Closing this issue as v2 now supports typescript 2.5+ an onwards.
@dherges Hi, I can confirm the enum works with
"ng-packagr": "2.0.0-rc.11"good job. Thank you.@skorunka : See https://github.com/dherges/ng-packagr/pull/395
@denver-HJS Sure, it’s good!
Here’s a draw-up of the transformation pipeline that is happening:
What you’re describing … you’d like to have just
tscas the very first step (no styles, no templates, no AoT metadata). So you go from*.tssources to es2015 (*.d.ts+*.js/ target: es2015 / module: es2015) and then run through the remainer of the rollup / tsc / uglify transformations?