"Cannot create property 'modifierFlagsCache'" when using string-based enums
See original GitHub issueFirst 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:
- Created 6 years ago
- Reactions:3
- Comments:23 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same problem and it’s worth to know that setting strings on
Enum
are available only since TypeScript version2.4
andng-packagr
is set to~2.3.3
inpackage.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 aclass
and addstatic
in front of eachenum
property2- Use
enum
as usual but simply add<any>
in front of eachenum
propertyI 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.