如何修复“ ERROR TypeError:Object(...)不是函数”?

时间:2019-04-26 16:23:33

标签: angular typescript ionic3

我正在创建一个新的应用程序,并且想在ionic 3中将一个数组解析为一个“ json”文件,但它显示ERROR TypeError: Object(...) is not a function;该如何解决此问题?

if(this.file) {
  console.log(this.userJsonUrl);
  this.file.writeFile(this.file.dataDirectory, "users.json", "Hello world",
    { replace: true }).then(done => alert('ok')).catch(err => alert('ok'))
  console.log('File created')
}

这是完整的错误

  

错误TypeError:Object(...)不是函数   在File.get [作为dataDirectory](index.js:649)
  在RegisterPage.webpackJsonp.204.RegisterPage.register(register.ts:62)
  在Object.eval [作为handleEvent](RegisterPage.ngfactory.js:116)
  在Object.handleEvent(core.es5.js:12023)
  在Object.handleEvent(core.es5.js:12756)
  在dispatchEvent(core.es5.js:8615)上
  在core.es5.js:9226
  在HTMLButtonElement。 (platform-b​​rowser.es5.js:2651)
  在t.invokeTask(polyfills.js:3)处
  在Object.onInvokeTask(core.es5.js:3881)

1 个答案:

答案 0 :(得分:0)

此错误与 @ionic-native/file 有关。

如果您使用@ionic-native/file安装npm install --save @ionic-native/file,请使用npm uninstall --save @ionic-native/file卸载它。

当您的应用程序使用Ionic 3时,应将@ionic-native/file @4一起安装。

npm install --save @ionic-native/file@4