ReferenceError: cordova is not defined

I am using ionic 3 and trying to export some data into csv format.

After imports I have
`

declare var cordova: any;

On click of a button I want to export some data into csv file. After clicking on the save button I am getting following exception

core.es5.js:1084 ERROR Error: Uncaught (in promise): ReferenceError: cordova is not defined
ReferenceError: cordova is not defined
    at home.ts:72
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.es5.js:4149)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.es5.js:4140)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at home.ts:72
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (core.es5.js:4149)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.es5.js:4140)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (core.es5.js:4140)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)
    at HTMLButtonElement.invoke (polyfills.js:3)
defaultErrorLogger @ core.es5.js:1084
ErrorHandler.handleError @ core.es5.js:1144
IonicErrorHandler.handleError @ ionic-error-handler.js:63
next @ core.es5.js:4778
schedulerFn @ core.es5.js:3851
SafeSubscriber.__tryOrUnsub @ Subscriber.js:238
SafeSubscriber.next @ Subscriber.js:185
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ core.es5.js:3837
NgZone.triggerError @ core.es5.js:4209
onHandleError @ core.es5.js:4170
t.handleError @ polyfills.js:3
r.runGuarded @ polyfills.js:3
(anonymous) @ polyfills.js:3
n.microtaskDrainDone @ polyfills.js:3
o @ polyfills.js:3
invoke @ polyfills.js:3

Following is my method
`

exportData()
    {

      var finalCSV="shiva";

      this.platform.ready().then(() => {
        console.log('test');
        console.log(cordova.file.externalRootDirectory);
        cordova.file.writeFile(cordova.file.externalRootDirectory, 'data.csv', finalCSV, true).then(function(result){
                alert('Success! Export created!');
              }, function(err) {
                console.log("ERROR");
              })
      });
    }
1 Like

What is this and where does it come from?

Why aren’t you using ionic-native?

I have the same issue but I am not using a native plugin.

Im literally tearing my hair out

I think @rapropos question on this matter is completely valid. Why are you not using ionic-native’s File api?

I have same problem, i want to ask you how are you resolve this problem , please tell me , thanks

1 Like