I am new to angular. I encounter this error in my index.component.ts
file.
Uncaught ReferenceError: __importDefault is not defined
Error screenshot attached
I got this problem when i was upgrading from angular 6 to angular 8, this is due to typescript,
since my TypeScript
version cannot be downgraded, I have overridden this method. adding below code to index.html
will resolve issue
GitHub Issue
<script> var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }</script>
I got this problem when upgrading from 8 to 9, thought it was a bug and even started reporting it in https://github.com/angular/angular/issues/35208, but I'm not sure it is really a bug. It might help someone having this error, though, so I'm posting here.
Short answer:
For some reason Because I updated Angular CLI without running the migrations (due to some very particular constraints I had), my package.json
was like this (those dependencies were left behind):
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.20",
"@angular-devkit/build-ng-packagr": "~0.803.20",
....
After changing it to the versions below, the problem is gone The problem wouldn't happen if they were as follows:
"devDependencies": {
"@angular-devkit/build-angular": "~0.900.1",
"@angular-devkit/build-ng-packagr": "~0.900.1",
....
Keep in mind that I show the wrong/right package versions here so it's easy to identify the symptoms, but I do not recommend you updating them manually, please run the CLI migration (as explained in the ticket) and they will be updated correctly.
This fixed it for me.
Added these lines to polyfills.ts
:
const w: any = window
// Fix "missing __importDefault", as per https://github.com/angular/angular/issues/32215#issuecomment-543459862
w.__importDefault = (w && w.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With