shaungbhone's avatar

Spatie Laravel PDF error

I got an error with spatie laravel pdf. I already installed all requirement from docs. Using

- Mac
- Safari
- Herd
The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=`npm root -g` node '/Users/shaungbhone/Herd/weshop/vendor/spatie/browsershot/src/../bin/browser.cjs' '{"url":"file:\/\/\/var\/tmp\/89399023-0225763001727011898\/index.html","action":"pdf","options":{"path":"inovices.pdf","args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"printBackground":true}}'" failed. Exit Code: 127(Command not found) Working directory: /Users/shaungbhone/Herd/weshop/public Output: ================ Error Output: ================ sh: npm: command not found sh: node: command not found
0 likes
2 replies
LaryAI's avatar
Level 58

It looks like the error you're encountering is due to the system not being able to find the node and npm commands. This typically happens when the Node.js and npm binaries are not in your system's PATH. Here are the steps to resolve this issue:

  1. Ensure Node.js and npm are installed: First, make sure that Node.js and npm are installed on your system. You can check this by running the following commands in your terminal:

    node -v
    npm -v
    

    If these commands return a version number, then Node.js and npm are installed. If not, you need to install them.

  2. Install Node.js and npm: If Node.js and npm are not installed, you can install them using Homebrew. Run the following commands:

    brew install node
    
  3. Add Node.js and npm to your PATH: Ensure that the directory containing the Node.js and npm binaries is in your PATH. You can add the following lines to your shell configuration file (e.g., ~/.zshrc or ~/.bash_profile):

    export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
    

    After adding this line, reload your shell configuration:

    source ~/.zshrc  # or source ~/.bash_profile
    
  4. Verify the PATH: Confirm that the PATH is correctly set by running:

    echo $PATH
    

    Ensure that /usr/local/bin and /opt/homebrew/bin are included in the output.

  5. Run the command again: Now, try running the command again. It should be able to find node and npm.

Here is a summary of the steps in a script format:

# Check if Node.js and npm are installed
node -v
npm -v

# If not installed, install Node.js and npm using Homebrew
brew install node

# Add Node.js and npm to PATH
echo 'export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"' >> ~/.zshrc  # or ~/.bash_profile

# Reload shell configuration
source ~/.zshrc  # or source ~/.bash_profile

# Verify PATH
echo $PATH

After following these steps, the command should execute without the "command not found" error. If you still encounter issues, please provide additional details, and I'll be happy to assist further.

Please or to participate in this conversation.