berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.23k stars 732 forks source link

[Bug] Unable to use in NextJS 13 project - Cannot statically analyse 'require(…, …)' in line 7 #829

Closed tagoad closed 10 months ago

tagoad commented 10 months ago

Describe the bug We are making a new project using Next JS 13 and are having issues with using the StealthPlugin. We can use Puppeteer Extra just fine, but when we import the StealthPlugin we get the following error at runtime:

error ./node_modules/clone-deep/utils.js Cannot statically analyse 'require(…, …)' in line 7

Import trace for requested module: ./node_modules/clone-deep/utils.js ./node_modules/clone-deep/index.js ./node_modules/merge-deep/index.js ./node_modules/puppeteer-extra-plugin/dist/index.cjs.js ./node_modules/puppeteer-extra-plugin-stealth/index.js

It appears to be an issue with a dependency, but hopefully there is some work around or fix as we can not scrape some of the sites we use to without this plugin.

Code Snippet

It literally just happens by importing, no specific code.

import StealthPlugin from "puppeteer-extra-plugin-stealth";
import puppeteer from "puppeteer-extra";
puppeteer.use(StealthPlugin())

Versions

System: OS: Windows 10 10.0.19045 CPU: (8) x64 AMD Ryzen 7 4700U with Radeon Graphics Memory: 5.26 GB / 39.42 GB Binaries: Node: 16.17.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD npmPackages: puppeteer: ^20.4.0 => 20.5.0 puppeteer-core: ^21.0.3 => 21.0.3 puppeteer-extra: ^3.3.6 => 3.3.6 puppeteer-extra-plugin-stealth: ^2.11.2 => 2.11.2

swapfox commented 10 months ago

try this in next.config.js

 experimental: {
    serverComponentsExternalPackages: [
      "puppeteer-extra",
      "puppeteer-extra-plugin-stealth",
      "puppeteer-extra-plugin-recaptcha",
    ],
  },
tagoad commented 10 months ago

try this in next.config.js

 experimental: {
    serverComponentsExternalPackages: [
      "puppeteer-extra",
      "puppeteer-extra-plugin-stealth",
      "puppeteer-extra-plugin-recaptcha",
    ],
  },

That worked. I can't believe it was that straight forward but I haven't seen that solution mentioned anywhere else online. Thank you so much!