markdown-pdf icon indicating copy to clipboard operation
markdown-pdf copied to clipboard

Unable to properly invoke markdown-pdf

Open FlorianLoch opened this issue 4 years ago • 12 comments

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

FlorianLoch avatar Jan 16 '20 10:01 FlorianLoch

Getting same error on windows

mikhail-barg avatar Feb 23 '20 08:02 mikhail-barg

Same error for me today on macOS Catalina

firasm avatar Mar 18 '20 17:03 firasm

Same error for me on Ubuntu

nad-au avatar Mar 25 '20 10:03 nad-au

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! 💪

annawidera avatar Mar 26 '20 16:03 annawidera

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

prochemo avatar Mar 27 '20 19:03 prochemo

-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.

nad-au avatar Mar 28 '20 03:03 nad-au

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 avatar Mar 29 '20 13:03 dijitaltrix

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 the phantomjs 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.

dijitaltrix avatar Mar 29 '20 14:03 dijitaltrix

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

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

JRMeyer avatar Apr 11 '20 00:04 JRMeyer

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

miklosz avatar Jun 01 '20 10:06 miklosz

Maybe add phantomjs as a requirement?

felixdivo avatar Sep 15 '20 07:09 felixdivo

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"

woshiluoyong avatar Feb 14 '22 07:02 woshiluoyong