0

I installed Spatie/Browsershot with composer and immediately got an error which is above my pay-grade... can someone please help.

 use Spatie\Browsershot\Browsershot;

 Browsershot::html('testing')->save('/public/assets/pdfs/example.pdf');

 The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=`npm root -g` node '/var/www/utopia/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/112376137-0051711001687420484\/index.html","action":"pdf","options":{"path":"\/public\/assets\/pdfs\/example.pdf","args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false}}'" failed. Exit Code: 127(Command not found) Working directory: /var/www/utopia Output: ================ Error Output: ================ sh: 1: npm: not found sh: 1: node: not found 

 Browsershot::html('testing')->save('/public/assets/pdfs/example.pdf')->setNodeBinary('/usr/bin/node')->setNpmBinary('/usr/bin/npm');

Same error.

I am using Docker. Is that the problem? What should I do?

Paul Godard
  • 1,055
  • 1
  • 14
  • 30

1 Answers1

0

If you installed node using Node Version Manager, you have to modify the include path, you can set it using the setIncludePath method.

Browsershot::html('Foo')
    ->setIncludePath('$PATH:/usr/local/bin')

Use echo $PATH and look for the path for your node.

Setting the include path can be useful in cases where node and npm can not be found automatically.

lance2k
  • 357
  • 1
  • 4
  • 14