[英]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.我在 VS Code 中使用 npm 模块,该模块与 node.js 一起使用并抛出
Uncaught ReferenceError: require is not defined
使用 VS Code 中提供的实时服务器扩展。
Related posts相关文章
Other posts suggest that I should use browserify.其他帖子建议我应该使用 browserify。 The tutorials that I found for browserify seemed to create an individual live server.
我为 browserify 找到的教程似乎创建了一个单独的实时服务器。 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.更多上下文:我正在使用 VS Code 实时服务器扩展运行一个网页,该扩展需要使用 puppeteer 模块从另一个网站获取数据。
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"
.本周我亲自与同样的问题进行了斗争,得出的结论是 puppeteer 库只能作为云 function 或通过使用
node "filename"
在终端本地运行它来工作服务器端。 Theres some security web protocols that dont allow scraping from the client side.有一些安全性 web 协议不允许从客户端抓取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.