Jspdf: Uncaught SyntaxError: Unexpected token ;

Created on 19 May 2015  ·  30Comments  ·  Source: MrRio/jsPDF

When I include this library from a webpack project,

import jsPDF from 'jsPDF';

Which imports jspdf.min.js

I get this error at the following line:

var o = t.parseBackgroundSize(e, n.image, r),
      s = t.parseBackgroundPosition(e, n.image, r, o),
      a = t.parseBackgroundRepeat(r);

I don't see the error here. Can anyone help me figure out why it's happening?

btw, I cannot use the jspdf.debug.js either because there are a ton of errors in it.

Most helpful comment

+1 Problem still occurs on latest release.

All 30 comments

I had the same problem, and ended up downloading the zip from https://parall.ax/products/jspdf, and using import JsPDF from 'dist/jspdf.amd.min.js';.

That page lets you download version 0.9.0-rc2. So this must be introduced in a recent release.

Are you using a tagged version or master?

That's probably it. I was using master. I'm going to try it with a tagged release today.

Cool, master is currently at 1.1.135 pre-release. Thanks for the heads up though, shall check

When I try installing v1.0.272, I get an error. The 1.1.135 installs just fine.

"jsPDF": "git://github.com/MrRio/jsPDF.git#v1.0.272",
npm ERR! addLocal Could not install /var/folders/r4/w_9zgq9123lgn_8h5q8rrttw0000gn/T/npm-20610-9a4cb773/1432750083351-0.4976797343697399/43eb0811568aae12c5258326921d7cda06424d59
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "i"
npm ERR! node v0.10.35
npm ERR! npm  v2.1.10
npm ERR! code EISDIR
npm ERR! errno 28

npm ERR! EISDIR, read

Oh... the earlier versions don't have a package.json file. Damn.

Did anyone ever figure this out? Have the same issue in Webpack using both master and 1.0.272 via NPM

It looks like the fact RequireJS is used plus the way that Webpack compiles the requires combined is the issue.

This:

... && (require_baseUrl_override = "../"), require.config({
        baseUrl: require_baseUrl_override,
        shim: {
            "plugins/standard_fonts_metrics": {
                deps: ["jspdf"]
            },
            "plugins/split_text_to_size": {
                deps: ["jspdf"]
            },
            "plugins/annotations": {
                deps: ["jspdf", "plugins/standard_fonts_metrics", "plugins/split_text_to_size"]
            },
            "plugins/outline": {
                deps: ["jspdf"]
            },
            "plugins/addimage": {
                deps: ["jspdf"]
            },
            "plugins/png_support": {
                deps: ["jspdf", "libs/png_support/png", "libs/png_support/zlib"]
            },
            "plugins/from_html": {
                deps: ["jspdf"]
            },
            "plugins/context2d": {
                deps: ["jspdf", "plugins/png_support", "plugins/addimage", "libs/css_colors"]
            },
            "libs/html2canvas/dist/html2canvas": {
                deps: ["jspdf"]
            },
            "plugins/canvas": {
                deps: ["jspdf"]
            },
            html2pdf: {
                deps: ["jspdf", "plugins/standard_fonts_metrics", "plugins/split_text_to_size", "plugins/png_support", "plugins/context2d", "plugins/canvas", "plugins/annotations", "libs/html2canvas/dist/html2canvas"]
            },
            "test/test_harness": {
                deps: ["jspdf", "jspdf.plugin.standard_fonts_metrics", "jspdf.plugin.split_text_to_size"]
            }
        },
        paths: {
            html2pdf: "libs/html2pdf"
        }
    });

Is compiled into this:

... && (require_baseUrl_override = "../"), ;;

Notice the RequireJS portion is the culprit (seems weird to leverage RequireJS for this), since _require_ is a keyword in node. I tried changing it to a different variable name and that prevented it from disappearing, however it then gave me the error of "could not read config of undefined", so its not as simple as a variable rename. That said, if this can be reworked to avoid the use of the _require_ keyword, I think it it'll work.

I resolved this temporarily by forking working version 0.9.0, then adding package.json file in the fork and using this line in my project package.json:
"jspdf": "git://github.com/pavestru/jsPDF.git#v0.9.1",

Has anyone come up with a solution to this issue besides forking it?

I tried installing both through npm and bower... had an issue using bower (which is 1.1.135) and npm (version 1.0.272)
Unexpected token: punc (;) [./bower_components/jspdf/dist/jspdf.min.js:273,21892]

@pavestru thank you! though that is a depressing solution...

thank you @jonespen

@pavestru I'm using your 'solution' but is it only workable with v0.9.1? Because that's quite an old version. I'd like to use jsPDF-AutoTable for instance, but that doesn't work with v0.9.1

@cyberco that lib is pretty neat. Someone should get angry enough to do the fixing. Version 0.9.1 does not have this issue but a different one that was easier to "fix".

@cyberco If something doesn't work in jspdf-autotable with version v0.9.x, feel free to submit an issue there. The current plan is to support all major versions of jspdf plus @pavestru's fork.

Is this all working now in the latest release?

This may or may not relate to another issue documented here – https://github.com/MrRio/jsPDF/issues/684

@MrRio It's still broken on current release. It does work when building from master thought

Problem persists with the current release when used with webpack.

+1 Problem still occurs on latest release.

https://github.com/MrRio/jsPDF/pull/774 works fine with webpack.

@MrRio The npm release is unusable due to that issue. Will there be a npm release including https://github.com/MrRio/jsPDF/pull/774 in the near future?

I still can't use jsPDF with webpack... :\

I just installed jspdf with webpack today and when I require it, it throws this exception.

@MrRio Any update on when this will be fixed?

from webpack
import jsPDF from 'jspdf'' yields Uncaught SyntaxError: Unexpected token ;

same for me..

How does 1.3.x look?

Version 1.3 works perfectly! Both with webpack, browserify and requirejs.

👍 Great! We'll add automated tests for these inclusions going forward

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mellisa0109 picture mellisa0109  ·  3Comments

sajesh1985 picture sajesh1985  ·  5Comments

arulmb0136 picture arulmb0136  ·  4Comments

glaier picture glaier  ·  3Comments

MaxCodeDE picture MaxCodeDE  ·  4Comments