0

I am using React, Typescript and I want to create a web scraper using Playwright.

My code is:

const playwright = require('playwright');

export async function OpenPage() {

    const browser = await playwright.chromium.launch({
        headless: false
    });
    const page = await browser.newPage();
    await page.goto('https://returnstring.com');
    await page.waitForTimeout(5000);
    await browser.close();
}

My tsconfig.json file :

{
  "compilerOptions": {
      "target": "es5",
      "lib": [
        "dom",
        "dom.iterable",
        "esnext"
      ],
      "allowJs": true,
      "skipLibCheck": true,
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true,
      "strict": true,
      "forceConsistentCasingInFileNames": true,
      "noFallthroughCasesInSwitch": true,
      "module": "esnext",
      "moduleResolution": "node",
      "resolveJsonModule": true,
      "isolatedModules": true,
      "noEmit": true,
      "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

When I run the command

npm start

I get a page full of errors starting with

Compiled with problems:

ERROR in ./node_modules/playwright-core/lib/client/android.js 8:33-46

Module not found: Error: Can't resolve 'fs' in 
'C:\git_bc\Blockchain\Huron\huron\node_modules\playwright-core\lib\client'


ERROR in ./node_modules/playwright-core/lib/client/artifact.js 8:33-46

Module not found: Error: Can't resolve 'fs' in 
'C:\git_bc\Blockchain\Huron\huron\node_modules\playwright-core\lib\client'


ERROR in ./node_modules/playwright-core/lib/client/browserContext.js 15:33-46

Module not found: Error: Can't resolve 'fs' in 
'C:\git_bc\Blockchain\Huron\huron\node_modules\playwright-core\lib\client'


ERROR in ./node_modules/playwright-core/lib/client/clientHelper.js 9:33-46

I read that Playwright cannot transpile tsconfig.json, but I didn't manage to solve the problem. Any ideas will be welcome.

user3417479
  • 1,830
  • 3
  • 18
  • 23
  • What dooes React have to do with Puppeteer? You may be confusing browser and server code. See [How to run Puppeteer code in any web browser?](https://stackoverflow.com/questions/54647694/how-to-run-puppeteer-code-in-any-web-browser) – ggorlen Oct 02 '22 at 14:47
  • Hi! could you find a solution for this? I'm having the same problem – Over Martinez Feb 25 '23 at 20:12
  • 1
    @OverMartinez I cannot use react with Playwright. Playwright runs only on the server side. Use .NET or nodejs – user3417479 Mar 08 '23 at 20:35

0 Answers0