← Back to Discord Forum

change playwright default from typescript to javascript

So our team decided on JS for the language everyone is using, I can change everything in my suite. But when new people are pulling down the repo I want to make sure playwright is setup for javascript not typescript. Do I have to uninstall playwright and then reinstall to change the settings?

This thread is trying to answer question "Does the user have to uninstall and reinstall Playwright to change the settings from TypeScript to JavaScript?"

3 replies

What exactly are you referring to? If Playwright is configured once, it will continue to work with JS. Are you referring to the code generator?

When you first install playwright it asks coding language. Is this just to setup the initial files?

Yes this is only required once per project. Install browsers is required once per computer.


Switching from TypeScript to JavaScript in Playwright

No need to uninstall and reinstall Playwright to switch from TypeScript to JavaScript. Just tweak your project's configuration settings and scripts.

Modify tsconfig.json

First, head to your project's tests folder. If there's no tsconfig.json file, create one. Then, add or modify the compiler options:

  "compilerOptions": {
    "target": "ESNext",
    "module": "commonjs",
    "moduleResolution": "Node",
    "sourceMap": true,
    "outDir": "../tests-out"

These options tell TypeScript to target ESNext, use the CommonJS module system, generate source maps, and output transpiled JavaScript files into a tests-out directory.

Update package.json

Next, open your package.json file. In the "scripts" section, add or modify these scripts:

  "scripts": {
    "pretest": "<command-to-run-typescript> -p tests/tsconfig.json",
    "test": "<command-to-run-playwright> -c tests-out"

Replace <command-to-run-typescript> with a command to run TypeScript compilation on your tests, like "tsc --incremental" or "npx tsc --incremental". Replace <command-to-run-playwright> with a command to run Playwright tests, like "playwright test" or "npx playwright test".

The pretest script runs TypeScript compilation on your tests using the tsconfig.json file. The test script executes the JavaScript tests in the tests-out directory.

After saving these changes, run npm run test to build and run your tests using JavaScript instead of TypeScript.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.