0

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:

  1. Restarting TypeScript server in VS Code.
  2. Ensuring the test file is a module.
  3. Including "types": ["node"] & "lib": ["esnext"] in tsconfig.json.
  4. Installing @types/node locally.

Why does VS Code still show Cannot find name "Buffer" and not suggest in IntelliSense, even though my test runs fine?

2
  • Did you check in your project's node_modules folder to make sure the types for Playwright are in there? Commented Nov 15 at 21:38
  • Yes, I checked inside my node_modules folder and both type packages node_modules/@types/node & node_modules/@playwright/test are present. Commented Nov 17 at 10:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.