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.