title: Puppeteer - TypeError: require(...) is not a function
body: <p>I've started using puppeteer to test a login form, I've tried the following code but I get this errors in vs terminal when I try to run the script</p>
  <p>index.js</p>
  <pre><code>#!/usr/bin/env node
  
  require('dotenv').config()
  const puppeteer = require('puppeteer')
  
  (async () =&gt; {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.google.com');
    // other actions...
    //await browser.close();
  })();
  
  </code></pre>
  <pre><code>(async () =&gt; {
  ^
  
  TypeError: require(...) is not a function
      at Object.&lt;anonymous&gt; (/Users/dev/Desktop/fuserbot/index.js:30:1)
      at Module._compile (node:internal/modules/cjs/loader:1108:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
      at Module.load (node:internal/modules/cjs/loader:973:32)
      at Function.Module._load (node:internal/modules/cjs/loader:813:14)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
      at node:internal/main/run_main_module:17:47
  </code></pre>
  <p>The code is the same of the example provided on the puppeteer documentation. As you can see I'm trying to make a cli script. If I try with my custom code, I will get this error instead</p>
  <p>index.js</p>
  <pre><code>#!/usr/bin/env node
  
  require('dotenv').config();
  const puppeteer = require('puppeteer');
  
  (async () =&gt; {
      //
      const browser = await puppeteer.launch();
      //
      const page = await browser.newPage();
      //
      page.setRequestInterception(true);
      //
      page.on('request', (request) =&gt; {
          console.log(request.url(), request.headers(), request.method(), request.postData());
      });
      //
      await page.goTo('https://www.examplesite.com');
      //
      await page.type('#email', process.env.MY_EMAIL, {delay: 2000});
      await page.type('#pass', process.env.MY_PASS, {delay: 2000});
      //
      await page.click('button[type=&quot;submit&quot;]');
      //
      await page.waitForNavigation();
  
      console.log('New url', page.url());
  })();
  </code></pre>
  <pre><code>    const page = browser.newPage();
                           ^
  
  TypeError: browser.newPage is not a function
      at /Users/dev/Desktop/fuserbot/index.js:12:26
      at Object.&lt;anonymous&gt; (/Users/dev/Desktop/fuserbot/index.js:30:3)
      at Module._compile (node:internal/modules/cjs/loader:1108:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
      at Module.load (node:internal/modules/cjs/loader:973:32)
      at Function.Module._load (node:internal/modules/cjs/loader:813:14)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
      at node:internal/main/run_main_module:17:47
  </code></pre>
  <p>What's wrong with the code?</p>