简体   繁体   中英

How to run npm module (puppeteer) in a VSCode chrome live-server?

The problem

I am using a npm module in VS Code which works with node.js and throws a Uncaught ReferenceError: require is not defined when using the live-server extension offered in VS Code.

Related posts

Other posts suggest that I should use browserify. The tutorials that I found for browserify seemed to create an individual live server. I am looking for a solution (if possible) that would allow me to use the live-server extension. (I don't quite understand how to create my own server- I am using the live-server extension because that is what I am familiar with so far. I am open to further suggestions.)

More Context: I am running a webpage using the VS Code live-server extension that needs to get data from another website using the puppeteer module.

I personally battled with this same issue this week and came to the conclusion that the puppeteer library can only work server side as a cloud function or by running it locally in your terminal using node "filename" . Theres some security web protocols that dont allow scraping from the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM