开发者问题收集

TypeError:对象原型只能是对象或为空:在 Ionic3 中未定义

2020-01-08
1166

在为我的 Ionic3 项目运行 ionic cordova build android --prod 时,我遇到了以下错误。仅使用 ionic cordova build android 不会出现任何错误。

ionic-app-script task: "build" 
TypeError: Object prototype may only be an Object or null: undefined 
TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at Object.__extends (/Users/.../node_modules/tslib/tslib.js:64:9)
    at /Users/.../node_modules/@angular/compiler-cli/src/ngtsc/indexer/src/template.js:115:17
    at /Users/.../node_modules/@angular/compiler-cli/src/ngtsc/indexer/src/template.js:314:6
    at /Users/.../node_modules/@angular/compiler-cli/src/ngtsc/indexer/src/template.js:3:17
    at Object.<anonymous> (/Users/.../node_modules/@angular/compiler-cli/src/ngtsc/indexer/src/template.js:9:3)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
[ERROR] An error occurred while running subprocess ionic-app-scripts.

我已尝试 此处 上的所有解决方案,但均无效。

以下是我的离子详细信息。

Ionic:

   Ionic CLI          : 5.4.13 (/Users/meuser/.nvm/versions/node/v12.6.0/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.9
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.1.0, ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 1.1.1, (and 18 other plugins)

Utility:

   cordova-res : 0.8.1
   native-run  : 0.3.0

编辑:

有关 ng v 的详细信息

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.23
@angular-devkit/build-optimizer   0.0.35
@angular-devkit/core              8.3.23
@angular-devkit/schematics        8.3.23
@angular/cli                      8.3.23
@angular/compiler-cli             8.2.12
@angular/fire                     5.3.0
@schematics/angular               8.3.23
@schematics/update                0.803.23
rxjs                              6.5.4
typescript                        3.7.5
webpack                           3.12.0

package.json

  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "^8.2.12",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
}
2个回答

终于找到问题所在。我根据自己的 Angular 版本将 "@angular/compiler-cli": "^8.2.12" 更改为 "@angular/compiler-cli": "5.2.11" ,一切正常。

Tapas Mukherjee
2020-01-21

删除您的 node_modules 文件夹。 删除您的平台 android 文件夹(整个平台文件夹或仅 android 文件夹)。

 Run npm install

添加平台 android

ionic cordova platform add android

再次构建您的应用

ionic cordova build android --prod
hi hi
2020-01-21