I am using TypeScript 5+ with Playwright and module: "nodenext" in my tsconfig.json:
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
// "rootDir": "./src",
// "outDir": "./dist",
// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "nodenext",
"target": "esnext",
"types": ["@playwright/test", "node"],
// For nodejs:
"lib": ["esnext"],
"moduleResolution": "nodenext",
// "types": ["node"],
// and npm install -D @types/node
// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,
// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": false,
// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,
// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
},
"include": ["tests/**/*.ts",
"playwright.config.ts",
"tests-examples/demo-todo-app.spec.ts",
"tests/example.spec.ts"]
}
I installed the Node type definitions & Playwright:
npm install --save-dev @types/node @playwright/test typescript
package.json:
{
"name": "my-project",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.56.1",
"@types/node": "^24.10.1",
"typescript": "^5.9.3"
}
}
Test file:
import {test, expect} from '@playwright/test';
test('File Upload', async ({page}) => {
await page.goto('https://practice.expandtesting.com/upload');
await page.locator('input#fileInput').setInputFiles({
name: 'testfile.txt',
mimeType: 'text/plan',
buffer: Buffer.from('Sample test')
});
await page.locator('button#fileSubmit').click();
await page.waitForTimeout(3000);
})
VS Code shows 'Cannot find name "Buffer"' and does not suggest Buffer in IntelliSense. Playwright test runs fine, so this seems like a TypeScript/IDE issue.
I have tried:
- Restarting TypeScript server in VS Code.
- Ensuring the test file is a module.
- Including
"types": ["node"]&"lib": ["esnext"]intsconfig.json. - Installing
@types/nodelocally.
Why does VS Code still show Cannot find name "Buffer" and not suggest in IntelliSense, even though my test runs fine?
node_modulesfolder to make sure the types for Playwright are in there?