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

时间:2020-01-08 20:00:42

标签: cordova ionic-framework ionic3

为我的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.

我已经尝试了here上的所有解决方案,但无法正常工作。

以下是我的离子细节。

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 (cordova-lib@9.0.1)
   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 个答案:

答案 0 :(得分:1)

最后找到了问题。根据我的角度版本,我将"@angular/compiler-cli": "^8.2.12"更改为"@angular/compiler-cli": "5.2.11",并且效果很好。

答案 1 :(得分:0)

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

 Run npm install

添加平台android

ionic cordova platform add android

再次构建您的应用

ionic cordova build android --prod