Skip to content
This repository was archived by the owner on Jul 24, 2026. It is now read-only.
This repository was archived by the owner on Jul 24, 2026. It is now read-only.

Canvas2ImagePlugin.js:10Uncaught ReferenceError: module is not defined #65

Open

Description

@sornanun

I work on ionic framework. I added canvas2ImagePlugin to my project and link it in index.html.
But I have some problem that I don't know how to fix. I'm a beginner with ionic and angularJS.

Error : Canvas2ImagePlugin.js:10Uncaught ReferenceError: module is not defined

module.exports = {   /// I got error this line.
    saveImageDataToLibrary:function(successCallback, failureCallback, canvasId) {
        // successCallback required
        if (typeof successCallback != "function") {
            console.log("Canvas2ImagePlugin Error: successCallback is not a function");
        }
        else if (typeof failureCallback != "function") {
            console.log("Canvas2ImagePlugin Error: failureCallback is not a function");
        }
        else {
            var canvas = (typeof canvasId === "string") ? document.getElementById(canvasId) : canvasId;
            var imageData = canvas.toDataURL().replace(/data:image\/png;base64,/,'');
            return cordova.exec(successCallback, failureCallback, "Canvas2ImagePlugin","saveImageDataToLibrary",[imageData]);
        }
    }
  };

and I will use this code in my controller.js to save image to mobile storage.

var canvas = document.createElement( 'pwCanvasMain' );
        var ctx = canvas.getContext( '2d' );
        void ctx.drawImage( this, 0, 0, img.width, img.height);
        var dataURI = canvas.toDataURL().replace( /data:image\/png;base64,/, '' );
        function successCallback( result ) {
            q.resolve( 'file:///' + result );
        }
        function failureCallback( err ) {
            console.error( err );
            q.reject( err );
        }
        cordova.exec( successCallback, failureCallback, "Canvas2ImagePlugin", "saveImageDataToLibrary", [dataURI] );

I want to convert my canvas as image then save on my mobile device storage. But my issue is module is not defined. Please help. Thanks.

Activity

  1. commonpike commented on Aug 15, 2018

    @commonpike

    @ghost, that is not the error OP was having ? Also, cordova.exec(..) using a dataURI as last argument is a working (though in this case apparently redundant) call on Android using 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions