6

I need to convert html to pdf and I am using jspdf 1.5.2. It shows the error Cannot read property 'charAt' of undefined (using with html2canvas).

When I try to install jspdf 1.5.3 I get this:

npm ERR! path git
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn git
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/eligrey/FileSaver.js.git
npm ERR! enoent 
npm ERR! enoent 
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

I have read the other threads and none of them are helpful.

Maen
  • 10,603
  • 3
  • 45
  • 71
Abdul Ahad
  • 1,221
  • 2
  • 16
  • 28

5 Answers5

7

With Version 1.5.3 of jsPDF they use a dependency directly from GitHUB. I'm assuming you're running the build in a CI? Either you install git + ssh or at that point return to version 1.5.2 of jsPDF. There's a bunch of issues in their bug tracker. This seems to be the relevant issue https://github.com/MrRio/jsPDF/issues/2208. It's marked fixed, but so far no new version 1.5.4.

Grmpfhmbl
  • 1,119
  • 12
  • 24
5

Try installing jspdf in git bash (GIT command line) using

npm i jspdf

4

I had the same problem. I solved installing git.

Natan
  • 301
  • 1
  • 8
4

For any passerby here because of html2pdf.js failing on CI, we're in the same boat.

It requires ^1.4.1, and resolves to 1.5.3 as of now, so either:

  • publish your own release on NPM rolling out the dependency fix,
  • install git on your Alpine image (docker: RUN apk add --no-cache git) and pray it'll pass through your enterprise firewall (it did not for me),
  • force 1.4.1 by requiring jsPDF in your package.json, and commit with the package-lock.json (worked for me).
Maen
  • 10,603
  • 3
  • 45
  • 71
  • 1
    Yeah downgrading to 1.4.1 worked for me (I'm using Bitbucket CI/Pipelines). Downgrading to 1.5.2 was causing a breaking issue with autotable so that was not an option. – cvb Jul 18 '19 at 15:32
  • Also using Bitbucket pipelines, downgrading jspdf to 1.4.1 worked for me. Apparently, pdf generating packages are dependent on the child packages of their peers, because uninstalling jspdf since I wasn't using it did nothing to help my case. – Benneee_ Jul 16 '20 at 14:31
0

I solved like this:

  1. Install Git.
  2. Open a new cmd window.
  3. Execute npm i jspdf.
Azametzin
  • 5,223
  • 12
  • 28
  • 46