Revo
Revo

Reputation: 13

How to fix 'ERROR TypeError: Object(...) is not a function'?

I am creating a new application and I want to parse an array into a "json" file in ionic 3 but it says ERROR TypeError: Object(...) is not a function; What can I do to solve this problem?

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')
}

and this is the full error

ERROR TypeError: Object(...) is not a function at File.get [as dataDirectory] (index.js:649)
at RegisterPage.webpackJsonp.204.RegisterPage.register (register.ts:62)
at Object.eval [as handleEvent] (RegisterPage.ngfactory.js:116)
at Object.handleEvent (core.es5.js:12023)
at Object.handleEvent (core.es5.js:12756)
at dispatchEvent (core.es5.js:8615)
at core.es5.js:9226
at HTMLButtonElement. (platform-browser.es5.js:2651)
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.es5.js:3881)

Upvotes: 0

Views: 1932

Answers (1)

Sudarshana Dayananda
Sudarshana Dayananda

Reputation: 5265

This error is related to @ionic-native/file.

If you install @ionic-native/file using npm install --save @ionic-native/file uninstall it using npm uninstall --save @ionic-native/file.

As your app is using Ionic 3, you should install @ionic-native/file with @4.

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

Upvotes: 1

Related Questions