CordovaPromiseFS is not defined

I can't get cordova-promise-fs to work in my cordova application.

What I have: index.html which includes one js file created by browserify. This js file contains content of cordovapromisefs.js, promiscuous.js and my own code, which is:

require('../node_modules/cordova-promise-fs/dist/CordovaPromiseFS.js');

var fs = CordovaPromiseFS({
            persistent: true, // or false
            storageSize: 20 * 1024 * 1024, // storage size in bytes, default 20MB 
            concurrency: 3, // how many concurrent uploads/downloads?
            Promise: require('../node_modules/promiscuous/promiscuous.js') // Your favorite Promise/A+ library! 
        });

(function () {
    "use strict";


    document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );

    function onDeviceReady() {
        console.log(fs);
    };  
} )();

I thought this should get the job done, but this leads me to "Uncaught ReferenceError: CordovaPromiseFS is not defined"

Would love to be pointed into the right direction.

Answers


You're using Browserify to build your bundle, so instead of requiring the already-bundled cordova-promise-fs/dist/CordovaPromiseFS.js file, require the module itself, like this:

var CordovaPromiseFS = require('cordova-promise-fs');

That will include the cordova-promise-fs/index.js file in your bundle which - unlike the already-bundled file - is a CommonJS module that exports the factory function.


try and assign the value that returns from require:

var CordovaPromiseFS = require('../node_modules/cordova-promise-fs/dist/CordovaPromiseFS.js');

you can also build CordovaPromiseFS as a browser library yourself, with webpack. the repo's readme suggests that you clone the source and run the available prepublish command:

npm install webpack -g
npm run-script prepublish

this command basically packs CordovaPromiseFS's index.js file and the packed dist file and exposes it to a variable (see the source).


Need Your Help

Do I need to reinstall Django for new virtualenv?

python django virtualenv virtualenvwrapper

Using virtualenvwrapper, I installed Django for one virtualenv. Now I can't reach it outside that environment. I want to be able to start new Django projects both outside any virtualenv, and inside...

How to test performance of database

sql sql-server database database-design relational-database

I created a database that have following table for user activities: