verumconsilium / laravel-browsershot

Browsershot wrapper for Laravel 5
MIT License
111 stars 20 forks source link

Destructuring assignment not working when downloading PDF #20

Closed sschilli closed 4 years ago

sschilli commented 4 years ago

Version info:

I am trying to download a PDF using the following:

return PDF::loadHtml($html)->download($filename);

When I do this, I get the following error:

[2020-06-19 17:52:02] local.ERROR: The command "PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node '/home/code/laravel/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/1176757848-0907304001592589121\/index.html","action":"pdf","options":{"path":"\/tmp\/594410754-0907194001592589121\/BrowsershotOutput1592589121G9jfs.pdf","args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false}}'" failed.

Exit Code: 8(Unknown error)

Working directory: /home/code/laravel/public

Output:
================

Error Output:
================

/home/code/laravel/vendor/spatie/browsershot/bin/browser.js:6
const [, , ...args] = process.argv;
      ^
SyntaxError: Unexpected token [
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3
 {"userId":39767,"exception":"[object] (Symfony\\Component\\Process\\Exception\\ProcessFailedException(code: 0): The command \"PATH=$PATH:/usr/local/bin NODE_PATH=`npm root -g` node '/home/code/laravel/vendor/spatie/browsershot/src/../bin/browser.js' '{\"url\":\"file:\\/\\/\\/tmp\\/1176757848-0907304001592589121\\/index.html\",\"action\":\"pdf\",\"options\":{\"path\":\"\\/tmp\\/594410754-0907194001592589121\\/BrowsershotOutput1592589121G9jfs.pdf\",\"args\":[],\"viewport\":{\"width\":800,\"height\":600},\"displayHeaderFooter\":false}}'\" failed.

Exit Code: 8(Unknown error)

This seems to indicate that destructuring assignment is not supported (which I think is new with ES6), but I have the minimum requirements and don't see what else I could be doing wrong. Any help with this?

rovertzxd commented 4 years ago

Hi @sschilli, the only way I was able to reproduce you're error was using Node <6.0.0, my best guess is that you have multiple versions of node installed on your system. Try specifying NODE_BINARY_PATH on you're .env file to make sure you are using the right binary