问题
I am new to angular. I encounter this error in my index.component.ts
file.
Uncaught ReferenceError: __importDefault is not defined
Error screenshot attached
回答1:
The following error is due to a bad version of typescript. You have to downgrade it.
Uncaught ReferenceError: __importDefault is not defined
Go to your package.json
file and downgrade it to 3.5.3
:
"devDependencies": {
// ...
"typescript": "3.5.3"
}
回答2:
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.
回答3:
I had the same problem when I update my project from angular 7 to 8.
after running ng serve
I git:
ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.6.0 but 3.6.2 was found instead.
After that:
"Uncaught ReferenceError: __importDefault is not defined.
I run npm install typescript@~3.4.0
and my problem was solve.
回答4:
I got this problem when upgrading from 6 to 8, this is due to typescript, and adding below code to index.html will resolve issue
<script> var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }</script>
来源:https://stackoverflow.com/questions/57662571/uncaught-referenceerror-importdefault-is-not-defined