signcl / docusaurus-prince-pdf

Docusaurus PDF generator using Prince XML
MIT License
135 stars 20 forks source link

Unable to build PDF due unexpected identifier #15

Closed joordy closed 1 year ago

joordy commented 2 years ago

Hi! After using your docusaurus-prince-pdf package for a while, I'd discovered a new problem. When creating a PDF using the following script:

npx docusaurus-prince-pdf -u https://docusaurus.io/docs

I've ran in the following problem:

file:///Users/jordy/node_modules/docusaurus-prince-pdf/index.js:9
import pkg from './package.json' assert { type: 'json' };
                                 ^^^^^^

SyntaxError: Unexpected identifier
    at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)
    at async link (internal/modules/esm/module_job.js:67:21)

Here is the source code to my documentation, which are generated using Docusaurus 2.0.0-beta.18. Could you please help me out? Thanks!

sparanoid commented 2 years ago

What Node.js version are you using? This syntax seems requires Node 16 or higher. You can try using it with Docker image.

sparanoid commented 2 years ago

Here's a working example for your site:

docker run --rm -it --init \
  -v $(pwd)/pdf:/app/pdf openbayes/docusaurus-prince-pdf \
  -u https://graduation-documentation.vercel.app/ \
  -s '.pagination-nav__item--next .pagination-nav__link' \
  --include-index
joordy commented 2 years ago

Hi!

I'm currently using Node v16.14, but still getting the error message. Also with older stable versions I still get the same error.

Also, the docker command won't work for me, I'm when running the following script:

docker run --rm -it --init \
  -v $(pwd)/pdf:/app/pdf openbayes/docusaurus-prince-pdf \
  -u https://graduation.jorrr.dev/ \
  -s '.pagination-nav__item--next .pagination-nav__link' \
  --include-index

And this is the result I'm getting


Error: Command failed: prince --no-warn-css --style=/app/print.css --input-list=./pdf/graduation.jorrr.dev.txt -o ./pdf/graduation.jorrr.dev.pdf 
/usr/local/bin/prince: exec: line 3: /usr/local/lib/prince/bin/prince: not found

    at ChildProcess.exithandler (node:child_process:398:12)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12) {
  code: 127,
  killed: false,
  signal: null,
  cmd: 'prince --no-warn-css --style=/app/print.css --input-list=./pdf/graduation.jorrr.dev.txt -o ./pdf/graduation.jorrr.dev.pdf '
}```

I even re-installed prince, without any succes..
chungminhtu commented 2 years ago

The problem happened because you don't install Prince first. You have to install it here: https://www.princexml.com/download/

After install, you have to test with prince --version to make sure it works.