Flatpickr issue "Cannot access 'e' before initialization"

Viewed 426

when I use ng serve to compile while development Flatpickr is working fine but when compile the whole application to deploy it on the server it gives the following error in the console

ReferenceError: Cannot access 'e' before initialization
at _ (main.84c9c5060af8f99f5713.bundle.js:formatted:95600)
at O (main.84c9c5060af8f99f5713.bundle.js:formatted:95625)
at w (main.84c9c5060af8f99f5713.bundle.js:formatted:95652)
at main.84c9c5060af8f99f5713.bundle.js:formatted:96326
at main.84c9c5060af8f99f5713.bundle.js:formatted:96441
at nC (main.84c9c5060af8f99f5713.bundle.js:formatted:96513)
at oC (main.84c9c5060af8f99f5713.bundle.js:formatted:96526)
at iC (main.84c9c5060af8f99f5713.bundle.js:formatted:96543)
at t.ngAfterViewInit (main.84c9c5060af8f99f5713.bundle.js:formatted:96580)
at Er (main.84c9c5060af8f99f5713.bundle.js:formatted:37872)

enter image description here

code I used to initialize Flatpickr is as below:-

 this.picker = flatpickr(this.flatpickrEl.nativeElement, {
        onChange: this.onDateChanged.bind(this),
        wrap: true,
        enableTime: true,
        dateFormat: "Y-m-d H:i"
    });

and tsconfig.json config is:-

"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
  "node_modules/@types"
],
"lib": [
  "es2017",
  "dom"
]

}

1 Answers

I appear to be having the same problem as you (using Flatpickr and Webpack). As far as I can tell, the issue is arising because in the function buildMonthSwitch there is an embedded function:

var shouldBuildMonth = function (month) { ... }`

This then gets referenced a few lines later:

if (!shouldBuildMonth(i))

For whatever reason, when this gets compiled to production and minified, the declaration minifier is attempting to inline shouldBuildMonth, but failing.

I believe this is a variant of this sort of issue, and the workaround appears to be to forbid your minifier from inlining functions.

Related