Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: __importDefault is not defined

I am new to angular. I encounter this error in my index.component.ts file.

Uncaught ReferenceError: __importDefault is not defined

Error screenshot attached

like image 482
Amely Avatar asked Aug 26 '19 17:08

Amely


3 Answers

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>
like image 131
Edison Avatar answered Nov 16 '22 01:11

Edison


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.

like image 34
BrunoJCM Avatar answered Nov 15 '22 23:11

BrunoJCM


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 }; }
like image 8
Kirill Groshkov Avatar answered Nov 16 '22 01:11

Kirill Groshkov