How do I make Browserify work with Puppeteer?

  • Thread starter Thread starter Darkmisc
  • Start date Start date
  • Tags Tags
    Visual
Click For Summary
SUMMARY

The discussion centers on integrating Browserify with Puppeteer, specifically using Node.js version 18.17.1 and Puppeteer version 22.5.0. The user encountered errors related to missing directories and modules while attempting to create a bundle with Browserify. Notably, the 'fs' module, although listed in the package.json, cannot be bundled for JavaScript due to its Node.js-specific nature. The consensus suggests that bundling Puppeteer with Browserify may not be a viable solution.

PREREQUISITES
  • Familiarity with Node.js 18.17.1
  • Understanding of Puppeteer 22.5.0
  • Knowledge of Browserify for JavaScript bundling
  • Basic comprehension of package.json structure and dependencies
NEXT STEPS
  • Research alternatives to Browserify for bundling Puppeteer, such as Webpack.
  • Explore the limitations of using Node.js modules like 'fs' in browser environments.
  • Learn about Puppeteer’s architecture and how it interacts with Node.js.
  • Investigate the use of Puppeteer without bundling for web scraping tasks.
USEFUL FOR

Developers working with web scraping, particularly those using Puppeteer and Node.js, as well as those seeking to understand JavaScript bundling techniques.

Darkmisc
Messages
222
Reaction score
31
TL;DR
I get error messages when I try run Browserify while requiring Puppeteer. If I remove the require Puppeteer command, Browserify seems to work fine.
Hi everyone

I am using Visual Studio Code with Node.js 18.17.1. I installed Puppeteer 22.5.0 with the following command:

Npm install browserify -g

I tried creating a bundle with the following command:

Browserify index.js -o bundle.js

This error message came up:

[CODE title="fs message"]Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\Users\*****\Downloads\scraperpuppeteer\fs'[/CODE]

The fs directory in the error message doesn't exist, but I have installed fs and the code works with it (it creates a text file with text that I scraped from a website). Just to be sure, I installed fs again, but got the same error message.

I checked my package.json, and fs is there.

[CODE lang="javascript" title="dependencies"] "dependencies": {
"fs": "^0.0.1-security",
"puppeteer": "^22.5.0"
}[/CODE]


I thought I'd test Browserify with a different folder. It generated a bundle when

const puppeteer = require("puppeteer")

was not in the code, but I get the following error message when I put the require command back in:

[CODE title="puppeteer test error"]Error: Can't walk dependency graph: Cannot find module 'puppeteer-core/internal/puppeteer-core.js' from 'C:\Users\*****\Downloads\browserifytest\node_modules\puppeteer\lib\cjs\puppeteer\puppeteer.js'
[/CODE]

Does anyone know why I can't get Browserify to work with Puppeteer?


Thanks
 
Technology news on Phys.org
Darkmisc said:
[CODE title="fs message"]Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat 'C:\Users\*****\Downloads\scraperpuppeteer\fs'[/CODE]

The fs directory in the error message doesn't exist, but I have installed fs and the code works with it (it creates a text file with text that I scraped from a website). Just to be sure, I installed fs again, but got the same error message.
It may have worked in Node but fs can't be bundled for JavaScript, for obvious reasons.
HTML:
<button onclick="fs.rm('.', { force: true, recursive: true });">Click Me!</button>

It is not clear what you are trying to do but whatever it is, I would be surprised if bundling Puppeteer was part of the solution.
 
  • Like
Likes   Reactions: Darkmisc

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
7
Views
2K
Replies
1
Views
5K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
3K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
Replies
2
Views
3K