1

my problem is the following: I'm trying to run a JS function with a HTML button, but this error appears each time I click the button:

Uncaught (in promise) ReferenceError: require is not defined

Im pretty sure that it is because I'm using Puppeteer in my JS file, and the function which the button executes uses it.

const puppeteer = require('puppeteer');

I have the import on the top of the file, but I think HTML only executes the function and doesn't read the import.

So the thing here is, can I dynamically import the module inside my function?

Thanks in advance!

Oto
  • 121
  • 5
  • 2
    "requires" are not expected to work in the browser, that is backend code. Maybe you can try some of [these](https://stackoverflow.com/questions/71097457/use-puppeteer-with-imgui-js). There are some failed attempts to try to make puppeteer worl in the browser. Good luck :) – rustyBucketBay Feb 28 '22 at 15:53
  • 2
    Are you using node.js? 'Require' will not work in a typical js file that you use in a web browser. – Wojtek322 Feb 28 '22 at 15:55
  • 2
    Puppeteer is a headless browser, it is used to control Chrome and is a Node module. It's not meant to be run in a browser – Jeremy Thille Feb 28 '22 at 16:10

0 Answers0