Are you encountering the dreaded Cannot find module puppeteer
error when trying to run Grover? If you’re using ActiveJob with deployment tools like Tomo, Capistrano, or Mina, you’re not alone. Let’s dive into the problem and its solution.
Our project uses:
When attempting to run a screenshot service through GoodJob, you might encounter this error:
Error: Grover::DependencyError: Cannot find module 'puppeteer'. You need to add it to '/package.json' and run 'npm install'
This occurs because Grover can’t locate the Puppeteer module in the deployed environment.
The key is to tell Grover where to find the root path of your application in the production environment. Here’s how:
config/initializers/grover.rb
Grover.configure do |config|
config.options = {}
config.options[:root_path] = '/home/your_username/sites/your_app_name/current' if Rails.env.production?
end
Replace your_username
and your_app_name
with your actual deployment path details.
By setting the root_path
option, you’re explicitly telling Grover where to look for the Puppeteer module in your production environment. This bypasses the issue of Grover not being able to automatically detect the correct path when running as a background job.
https://github.com/Studiosity/grover/issues/96#issuecomment-752787204