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 create property 'modifierFlagsCache'" when using string-based enums

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
ghiscodingcommented, Oct 23, 2017

I have the same problem and it’s worth to know that setting strings on Enum are available only since TypeScript version 2.4 and ng-packagr is set to ~2.3.3 in package.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 enum to a class and add static in front of each enum property

export class Order { 
  static Asc = 'Asc'; 
  static Desc = 'Desc' 
}

2- Use enum as usual but simply add <any> in front of each enum property

export enum Order { 
  Asc = <any>'Asc', 
  Desc = <any>'Desc' 
}

I 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.

2reactions
dhergescommented, Feb 21, 2018

Closing this issue as v2 now supports typescript 2.5+ an onwards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot create property on string - javascript
I have stumbled on a weird issue when trying to recursively set properties on an empty object with the following code:.
Read more >
How To Solve This? (Uncaught Typeerror Cannot Create ...
(Uncaught Typeerror Cannot Create Property Disabled On String) ... Cannot create property 'modifierFlagsCache' when using stringbased enums ...
Read more >
Houdini Gets Substance Integration
Houdini is a 3D content creation application with a procedural bent. Substance is a Physically Based Renderer (PBR) for creating real world materials...
Read more >
web3js - Cannot create property 'from' on string
I think that string is not the address, is the object where it's trying to assign the "from" property. I suppose is the...
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