You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装运行Browsershot时触发SyntaxError语法错误求助

Fixing Browsershot's SyntaxError: Unexpected token ( Error

What's Causing the Issue?

The error you're seeing:

SyntaxError: Unexpected token (

is directly related to your Node.js version being too old. Browsershot's browser.js uses async/await syntax, which is only supported in Node.js 7.6 and above. When you install Node.js via yum on most RHEL/CentOS systems, you get an outdated version (usually Node.js 6.x or lower) that doesn't support this modern JavaScript feature.

Also, I noticed a small typo in your Composer command: you used satie/browsershot instead of the correct package name spatie/browsershot—we'll fix that too.

Step-by-Step Fix

  1. Uninstall the old Node.js and npm
    First, remove the outdated versions installed via yum:

    yum remove nodejs npm -y
    
  2. Install NVM (Node Version Manager)
    NVM lets you easily install and switch between different Node.js versions. Run this command to install it:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    

    Then load NVM into your current shell session:

    source ~/.bashrc
    
  3. Install a supported Node.js version
    Install an LTS (Long-Term Support) version of Node.js that supports async/await (we'll use Node.js 18, which is stable and widely supported):

    nvm install 18
    nvm alias default 18
    
  4. Verify your Node.js and npm versions
    Confirm you're running the correct version:

    node -v # Should output something like v18.17.1
    npm -v # Should output a version compatible with Node 18, e.g., 9.6.7
    
  5. Fix the Composer package typo (if needed)
    If you installed the wrong package earlier, correct it:

    composer remove satie/browsershot
    composer require spatie/browsershot
    
  6. Reinstall Puppeteer (Browsershot's core dependency)
    Browsershot requires Puppeteer to handle browser automation. Install it globally:

    npm install puppeteer --global
    
  7. Test your Browsershot script again
    Run your browsershots.php script once more. The syntax error should be resolved, and your screenshot should save to the specified img/testasdf.png path.

内容的提问来源于stack exchange,提问作者Gregor Meier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:34:47