r.js error - Mismatched anonymous define() module: function () #289

sudodoki opened this Issue Jun 24, 2014 · 9 comments


None yet
6 participants

There's an issue with r.js when using jsPDF. For more info, please read this comment: jrburke/r.js#558 (comment)
As I can tell, the

r.js found multiple anonymous defines and skipped naming one of the define()s. This could also be bug

Is an issue, because you have https://github.com/MrRio/jsPDF/blob/master/dist/jspdf.debug.js#L1703-L1705, https://github.com/MrRio/jsPDF/blob/master/dist/jspdf.debug.js#L5673-L5675

Assume that's an issue caused by build setup you're using.

I have the same problem. As a workaround I'm defining jspdf modules separately:

    shim: {
        'jsPDF-addImage': {
            deps: ['jsPDF-core']

paths: {
        'jsPDF-core': '../bower_components/jsPDF/jspdf',
        'jsPDF-addImage': '../bower_components/jsPDF/jspdf.plugin.addimage',
        'jsPDF': 'lib/jspdf'

And in lib/jspdf.js:

'use strict';
/* Meta module to have the whole jspdf library available at once,
 * just by requiring this module. */

define(function(require) {
    var jsPDF = require('jsPDF-core'),
        addImage = require('jsPDF-addImage');

    return jsPDF;

With this configuration, requiring 'jsPDF' is enough. I'm even using almond and works fine.

I'm still trying to find a workaround to the fact that bower will not install the whole repository, thanks to the "ignore" section of bower.json

I've opened an issue in r.js asking which would be the best solution jrburke/r.js#699


diegocr commented Jun 25, 2014

With RequireJS it is needed to use the minimized version, as pointed in #122

Minimized version wouldn't help, in fact, I encountered issue there first. Presence of multiple anonymous defines are not affected by minification.

@diegocr This happens with both debug and minified version. Using RequireJS was partially addressed in #122 . However, this problem arises when building an optimized version of an application that uses jsPDF.

There should be a single anonymous define() in each file, see jrburke/almond#80 (comment) .

For me it would be just fine to remove "jspdf.js" and "jspdf.plugin.*" from the ignore section of bower.json. This allows jspdf modules to be required separately as I previously described in this same issue.

diegocr closed this in 82893ba Jun 25, 2014


diegocr commented Jun 25, 2014

Right guys, while #122 fixed a conflict with adler32, i missed there's another conflict with FileSaver.js

Commit 82893ba should fix that, i'll check some PRs before building new dist files.

diegocr added the Fixed label Jun 28, 2014

I'm still getting this error on the latest version of jsPDF.

Getting this error by merely including the file as follows on a mostly blank page:
script src="scripts/jsPDF-master/dist/jspdf.debug.js"></script

"Error: Mismatched anonymous define() module: function" which seems to be from RequireJS. It does not happen when I include jspdf.min.js in the same way.

adumat commented Jan 19, 2016

+1, i've same problem with last version.
on same page i have jspdf and d3.layout.cloud, on d3.layout.cloud parsing i've same error reported by @VaelVictus

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