【问题标题】:Uncaught TypeError: Object(...) is not a function in the browserUncaught TypeError: Object(...) is not a function in the browser
【发布时间】:2020-02-03 17:46:48
【问题描述】:

我正在尝试使用 Ionic Image Loader 进行图像加载和缓存。编译时没有错误,但在浏览器中显示以下错误。我正在从我的 package.json 文件中粘贴详细信息。我是离子和角度的新手。请告诉我如何解决此问题。

Uncaught TypeError: Object(...) is not a function  at index.js:1193 
at Module../node_modules/@ionic-native/file/index.js (index.js:1370) 
at __webpack_require__ (bootstrap:84) at Module../node_modules/ionic-image-loader/dist/image-loader.module.js (image-loader.module.js:1)    
at __webpack_require__ (bootstrap:84) at Module../node_modules/ionic-image-loader/dist/index.js (index.js:1) at __webpack_require__ (bootstrap:84)  
at Module../src/app/app-routing.module.ts (main.js:494) 
at __webpack_require__ (bootstrap:84) 
at Module../src/app/app.module.ts (app.component.ts:12)

我的 package.json 如下所示

    {
  "name": "blank",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@ionic-native/core": "^5.0.0-beta.14",
    "@ionic-native/file": "^4.20.0",
    "@ionic-native/file-transfer": "^5.20.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.7.1",
    "cordova-plugin-file": "6.0.2",
    "core-js": "^2.5.4",
    "ionic-image-loader": "^6.3.3",
    "rxjs": "^6.5.4",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "~0.801.2",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-file": {}
    }
  }
}

【问题讨论】:

  • @ionic-native/core@ionic-native/file 之间的版本很可能不匹配。
  • 我将@ionic-native/file 的版本更改为5.0.0。现在错误更改为未捕获错误:无法解析 ImageLoader 的所有参数:([object Object],?,[object Object],[object Object])。在 CompileMetadataResolver._getDependenciesMetadata (compiler.js:20166) 在 CompileMetadataResolver._getTypeMetadata (compiler.js:20061) 处的 syntaxError (compiler.js:2175)
  • 删除了 node_module 并运行了 npm install 但它也没有工作。
  • 更新了版本 "@ionic-native/core": "^5.0.0", "@ionic-native/file": "^5.0.0"
  • 那么npm i ionic-image-loader@beta 应该可以工作了。

标签: angular ionic-framework imageloader


【解决方案1】:

这很可能是因为版本不匹配。

@ionic-native/fileionic-image-loader does not yet support v5 的当前版本,但有a beta version available 哪个does support it

确保所有@ionic-native/* 软件包都在同一个主要版本上。如果要使用 beta 版本,请使用 v5,否则使用 v5 和最新稳定版ionic-image-loader

【讨论】:

  • 非常感谢。这是版本不匹配。当我使用 Beta 版时,它可以工作。
  • 不客气。请不要忘记mark the answer as accepted
相关资源