简体   繁体   English

如何在 VSCode chrome live-server 中运行 npm 模块(puppeteer)?

[英]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.

相关问题 使用npm live-server时是否清除localStorage? - Does the localStorage get cleared when working with npm live-server? 使用 npm 安装 live-server 包时出错。 `npm audit` 无助于解决问题 - Getting error while installing live-server package using npm. `npm audit` is not helping to fix the problem 如何在运行实时服务器的情况下在 Visual Studio Code 中调试 JavaScript - How to Debug JavaScript in Visual Studio Code with live-server Running vscode live-server extension v5.6.1 无法解析 'axios' JavaScript 导入 - vscode live-server extension v5.6.1 fails to resolve 'axios' JavaScript import 是什么导致npm live-server停止检测文件更改? - What would cause npm live-server to stop detecting file changes? npm live-server安装:symlink错误(即使以root / admin身份运行) - npm live-server install: symlink error (even when running as root/admin) 未找到 NPM 模块 - Puppeteer - NPM Module Not Found - Puppeteer 如何使用Sublime Text 3从Windows机器中杀死Live Server - How to kill the live-server from windows machine using sublime text 3 如何在LIVE-SERVER上使用Javascript查找当前的html文件页面名称 - How can I find the current html filepage name using Javascript, on a LIVE-SERVER 如何关闭 Windows 上的 node.js 实时服务器? - How do I close a node.js live-server on Windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM