无法安装 jspdf 1.5.3

IT技术 javascript reactjs npm jspdf html2canvas
2021-05-14 13:10:42

我需要将 html 转换为 pdf,我使用的是 jspdf 1.5.2。它显示错误无法读取未定义的属性“charAt”(与 html2canvas 一起使用)。

当我尝试安装 jspdf 1.5.3 时,我得到了这个:

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 

我已经阅读了其他线程,但没有一个有帮助。

4个回答

在 jsPDF 1.5.3 版中,他们直接使用来自 GitHub 的依赖项。我假设您正在 CI 中运行构建?要么安装 git + ssh,要么在那时返回 jsPDF 的 1.5.2 版。他们的错误跟踪器中有很多问题。这似乎是相关问题https://github.com/MrRio/jsPDF/issues/2208它被标记为已修复,但目前还没有新版本 1.5.4。

我有同样的问题。我解决了安装git。

尝试在git bash(GIT 命令行)中安装 jspdf使用

npm我jspdf

对于由于 html2pdf.js 在 CI 上失败而在这里的任何路人,我们在同一条船上。

它需要 ^1.4.1,并且截至目前解析为 1.5.3,因此:

  • 在 NPM 上发布你自己的版本,推出依赖修复,
  • 在你的 Alpine 镜像上安装 git(docker: RUN apk add --no-cache git)并祈祷它能够通过你的企业防火墙(它不适合我),
  • 通过在 package.json 中要求 jsPDF 强制 1.4.1,并使用 package-lock.json 提交(对我有用)。