alanshaw / markdown-pdf

:page_facing_up: Markdown to PDF converter
https://npmjs.org/package/markdown-pdf
MIT License
2.71k stars 253 forks source link

Unable to properly invoke markdown-pdf #180

Open FlorianLoch opened 4 years ago

FlorianLoch commented 4 years ago

Hello, just updated and tried to use it again with very simple invocation:

markdown-pdf doc.md

I expected a doc.pdf to be created. Instead I got the following error message:

internal/validators.js:118
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received null
    at validateString (internal/validators.js:118:11)
    at normalizeSpawnArguments (child_process.js:406:3)
    at spawn (child_process.js:546:13)
    at Object.execFile (child_process.js:232:17)
    at WriteStream.<anonymous> (/usr/local/lib/node_modules/markdown-pdf/index.js:117:22)
    at WriteStream.emit (events.js:333:22)
    at finishMaybe (_stream_writable.js:697:14)
    at _stream_writable.js:673:7
    at WriteStream._final (internal/fs/streams.js:377:3)
    at callFinal (_stream_writable.js:666:10) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Aside it created an empty doc.pdf file, also indicating that it's not a permission issue on my system. I am using macOS Catalina.

Cheers, Florian

mikhail-barg commented 4 years ago

Getting same error on windows

firasm commented 4 years ago

Same error for me today on macOS Catalina

nad-au commented 4 years ago

Same error for me on Ubuntu

annawidera commented 4 years ago

Unfortunately same error for me on Catalina (10.15.3) today. Command: markdown-pdf PeakSpotting-csv-changes.md. markdown-pdf installed globally.

This tool looks very promising, hopefully, we will be able to resolve this issue! 💪

prochemo commented 4 years ago

by providing the current directory argument it worked for me. -c ./

nad-au commented 4 years ago

-c doesn't work for me. Which version are you using? I just dropped to v9.0.0 and is working fine with any arguments.

dijitaltrix commented 4 years ago

Same issue here on macos Mojave 10.14.6, I tried markdown-pdf v9.0.0 and v10.0.0

$ markdown-pdf readme.md 
$ markdown-pdf -c ./ readme.md

Same error but line 117

internal/validators.js:117
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received null
    at validateString (internal/validators.js:117:11)
    at normalizeSpawnArguments (child_process.js:406:3)
    at spawn (child_process.js:542:16)
    at Object.execFile (child_process.js:232:17)
    at WriteStream.<anonymous> (/opt/local/lib/node_modules/markdown-pdf/index.js:117:22)
    at WriteStream.emit (events.js:333:22)
    at finishMaybe (_stream_writable.js:687:14)
    at _stream_writable.js:664:5
    at WriteStream._final (internal/fs/streams.js:311:3)
    at callFinal (_stream_writable.js:657:10) {
  code: 'ERR_INVALID_ARG_TYPE'
dijitaltrix commented 4 years ago

This may be related to #181

Checking the code in index.js I found my opts.phantomPath was empty on line 117.

PhantomJS is required to render the PDF so you must have it installed on your system and markdown-pdf must be told where it is.

The solution In #142 almost worked for me but npm would not install phantomjs-prebuilt properly I am not an expert in js or npm so I chose to copy it over manually.

sudo npm install -g phantomjs-prebuilt In my case the above fails but leaves the zip download in /tmp

Inside the zip is the bin folder with thephantomjs binary.

We can call markdown-pdf and tell it to use this binary with the -p option.

I chose to copy it next to the existing phantom/render.js file under the npm installed markdown-pdf folder: sudo cp phantomjs /opt/local/lib/node_modules/markdown-pdf/phantom/

By calling markdown-pdf with the -p option (tells it where to find phantomjs) it works! markdown-pdf readme.md -p /opt/local/lib/node_modules/markdown-pdf/phantom/phantomjs

You could hardcode this so you don't have to call it with the -p option every time. Just be aware this is considered bad practice as your changes will be overwritten.

In markdown-pdf/index.js above line 117 add the path to phantomjs - in my case: opts.phantomPath = '/opt/local/lib/node_modules/markdown-pdf/phantom/phantomjs';

I hope this helps until the PhantomJS install issue can be resolved.

JRMeyer commented 4 years ago

This answer from #181 worked for me on Ubuntu 18.04:

markdown-pdf -p $(which phantomjs) mymarkdown.md

miklosz commented 4 years ago

Windows: Error: ENOENT: no such file or directory... Looks like it cannot handle Windows path format

felixdivo commented 4 years ago

Maybe add phantomjs as a requirement?

woshiluoyong commented 2 years ago

This answer from #181 worked for me on Ubuntu 18.04:

markdown-pdf -p $(which phantomjs) mymarkdown.md

great, you need to install phantomjs first, run command: "npm install -g phantomjs" then look for the phantomjs installed path: "which phantomjs" last run convert command: "markdown-pdf -p /home/xxxxx/phantomjs test.md"