Last modified: Jun 30, 2025 By Alexander Williams
Fix Error: Cannot find module 'puppeteer'
If you see the error Cannot find module 'puppeteer', don't worry. This is a common issue in Node.js. It means Puppeteer is not installed or not found. Let's fix it step by step.
Table Of Contents
- Why does this error occur?
- Solution 1: Install Puppeteer
- Solution 2: Verify installation
- Solution 3: Global vs local installation
- Solution 4: Check package.json
- Solution 5: Clear npm cache
- Solution 6: Use correct Node.js version
- Solution 7: Rebuild dependencies
- Solution 8: Check file permissions
- Solution 9: Try puppeteer-core
- Solution 10: Verify import statement
- Conclusion
Why does this error occur?
The error happens when Node.js cannot locate the Puppeteer module. This usually occurs due to one of these reasons:
- Puppeteer is not installed
- Installation was incomplete
- Wrong project directory
- Node_modules is missing
Solution 1: Install Puppeteer
The simplest fix is to install Puppeteer. Run this command in your project directory:
npm install puppeteer
This will download Puppeteer and its dependencies. It might take a few minutes as it includes Chromium.
Solution 2: Verify installation
After installing, check if Puppeteer exists in your node_modules
. Run:
ls node_modules | grep puppeteer
You should see puppeteer listed. If not, try reinstalling.
Solution 3: Global vs local installation
Make sure Puppeteer is installed locally, not globally. Global installations can cause issues. Remove any global Puppeteer first:
npm uninstall -g puppeteer
npm install puppeteer --save
Solution 4: Check package.json
Ensure Puppeteer is listed in your package.json
dependencies. If not, add it manually:
"dependencies": {
"puppeteer": "^21.0.0"
}
Then run npm install
to install all dependencies.
Solution 5: Clear npm cache
A corrupted cache can cause installation issues. Clear it and reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
Solution 6: Use correct Node.js version
Puppeteer requires Node.js 16 or higher. Check your version:
node -v
If it's below 16, upgrade Node.js. You might also encounter similar issues with other modules like TypeScript or Webpack if using old Node versions.
Solution 7: Rebuild dependencies
Sometimes dependencies need rebuilding. Try:
npm rebuild
Solution 8: Check file permissions
Permission issues can prevent module access. Fix permissions in your project:
sudo chown -R $(whoami) node_modules
Solution 9: Try puppeteer-core
If you already have Chrome installed, use puppeteer-core
instead:
npm install puppeteer-core
Remember to configure it to use your existing Chrome. This is similar to how you might handle React dependencies.
Solution 10: Verify import statement
Ensure you're importing Puppeteer correctly in your code:
const puppeteer = require('puppeteer'); // CommonJS
// or
import puppeteer from 'puppeteer'; // ES Modules
Conclusion
The Cannot find module 'puppeteer' error is usually easy to fix. Most often, it's solved by reinstalling Puppeteer. Follow these steps one by one until the error disappears.
Remember to check your Node.js version, installation method, and file permissions. If you still face issues, check the Puppeteer documentation for version-specific solutions.