Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received null #210

Open
ORESoftware opened this issue Sep 13, 2022 · 9 comments

Comments

@ORESoftware
Copy link

here was my command:

markdown-pdf report-paper-3.md -o $(uuidgen)

I got this error

node:internal/validators:120
    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 new NodeError (node:internal/errors:372:5)
    at validateString (node:internal/validators:120:11)
    at normalizeSpawnArguments (node:child_process:505:3)
    at spawn (node:child_process:693:13)
    at Object.execFile (node:child_process:327:17)
    at WriteStream.<anonymous> (/Users/amills/.nvm/versions/node/v16.15.0/lib/node_modules/markdown-pdf/index.js:117:22)
    at WriteStream.emit (node:events:539:35)
    at finish (node:internal/streams/writable:754:10)
    at finishMaybe (node:internal/streams/writable:739:9)
    at afterWrite (node:internal/streams/writable:504:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

the error makes no sense to me :( :(

@ZloeSabo
Copy link

Having a similar error, I found that the code is not able to locate a phantomjs. So installing phantomjs-prebuilt fixed the issue for me.

@onekiloparsec
Copy link

Installing phantomjs-prebuilt didn't fix the issue for me. :-(

@larsvilhuber
Copy link

I can confirm that the solution by @ZloeSabo did not help in my case either. I'm a Node newbie, but here's the reproducible example (running on Docker image node:latest)

npm install -g markdown-pdf --ignore-scripts
npm install -g phantomjs-prebuilt
cd /tmp
git clone https://github.com/alanshaw/markdown-pdf
cd markdown-pdf
markdown-pdf README.md

which yields

node:internal/validators:163
    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 new NodeError (node:internal/errors:393:5)
    at validateString (node:internal/validators:163:11)
    at normalizeSpawnArguments (node:child_process:538:3)
    at spawn (node:child_process:736:13)
    at Object.execFile (node:child_process:341:17)
    at WriteStream.<anonymous> (/usr/local/lib/node_modules/markdown-pdf/index.js:117:22)
    at WriteStream.emit (node:events:525:35)
    at finish (node:internal/streams/writable:748:10)
    at finishMaybe (node:internal/streams/writable:733:9)
    at afterWrite (node:internal/streams/writable:507:3) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v18.11.0

Glad to try and help with debugging, but I'm normally useless on Node.

System:

  • Linux as host
  • node:latest ea9021b35904
  • Docker version 20.10.17-ce, build a89b84221c85

@ronaldbosma
Copy link

It worked for me after installing phantomjs-prebuilt and passing the path to the phantomjs.exe as the --phantom-path parameter.

Example:

markdown-pdf my-file.md --out my-file.pdf --phantom-path ...\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe

@animator
Copy link

Getting this error

% npm install -g phantomjs-prebuilt
npm WARN deprecated phantomjs-prebuilt@2.1.16: this package is now deprecated

and it is still not working.

@larsvilhuber
Copy link

I added export OPENSSL_CONF=/etc/ssl/ prior to running this as

markdown-pdf README.md --out test.pdf

and I no longer have errors.

@lucastheisen
Copy link

I had to supply both:

OPENSSL_CONF=/etc/ssl markdown-pdf \
  --phantom-path "${NODE_MODULES_DIR}/phantomjs-prebuilt/lib/phantom/bin/phantomjs" \
  --out test.pdf
  README.md

@Inouyasha
Copy link

The reason can't find file is markdown-pdf index.js line 17

  opts.phantomPath = opts.phantomPath || require('phantomjs-prebuilt').path

system can't find path by require function

So we intall the phantomjs-prebuilt by npm install phantomjs-prebuilt
After that, the problem maybe still happen, but now we can see the .path is from code in file node_modules\phantomjs-prebuilt\lib\phantomjs.js

/**
 * Where the phantom binary can be found.
 * @type {string}
 */
try {
  var location = require('./location')
  exports.path = path.resolve(__dirname, location.location)
  exports.platform = location.platform
  exports.arch = location.arch
} catch(e) {
  // Must be running inside install script.
  exports.path = null
}

We can see if the code can not work normally, the path will be null. What we need to do is just run install.js,
i.e. shell node ./install.js

which can check in file README.md
Then it can generate as you wish without any parameter.

@Steve235lab
Copy link

Having a similar error, I found that the code is not able to locate a phantomjs. So installing phantomjs-prebuilt fixed the issue for me.

Uninstall markdown-pdf first, then install phantomjs-prebuilt and markdown-pdf solved this in my environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants