question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] After upgrade to version - I'm getting the error with async functions: An async function or method in ES5/ES3 requires the 'Promise' constructor

See original GitHub issue

Context:

  • Playwright Version: 1.22.1
  • Operating System: Windows
  • Node.js version: 16.15.0
  • Browser: AlL
  • Extra: Tested with Webstorm IDE and with VSCode

Code Snippet

import test from "@playwright/test";

test.describe('Describe', async() => {

    test.beforeEach(async ({page}) => {
        await page.goto('');
    });

    test('Test', async({page}) => {
        await page.locator('').click();
    })
})

Describe the bug

The error started to appear after an upgrade to version 1.22. It requires the ‘Promise’ constructor. I didn’t see this error before an upgrade.

The error occurs in the VSCode: image

And also in the Webstorm IDE: image

I use the Playwright with typescript - should I need to take the advice of IDEs? Or maybe is it a bug? Because as I mentioned, I didn’t see these errors before an upgrade.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rwollcommented, May 19, 2022

@AlexKomanov You shouldn’t need lib. On 1.22, I used your code from https://github.com/microsoft/playwright/issues/14221#issue-1238645155 and your config https://github.com/microsoft/playwright/issues/14221#issuecomment-1128960207 but deleted the lib section. VSCode at first complained in the same way as your screenshot when I added the tsconfig, but I closed VSCode and re-opened and it was all good again. Can you check if closing and re-opening clears the errors?

NB: Aside: if you then go and add a process.env call, the VSCode typing might complain, but this is related to https://github.com/microsoft/playwright/pull/14230 which will be fixed shortly in a patch release.

Please re-open if I missed something or if restarting VSCode does not resolve the issue. Thanks!

0reactions
dhiegomagacommented, Oct 9, 2022

I’m having the same issue, tsc: Version 4.8.4, and tsconfig.json:

{
  "compilerOptions":{
    "target": "ES3"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ts An async function or method in ES5/ES3 requires the ...
[ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor ......
Read more >
Async and Await in JavaScript, the extension to a promise.
This function will operate a function asynchronously via the event loop using an implicit Promise to return its result. If you need a...
Read more >
Handling “A”-synchronousity in JS | by Anil Kumar | Medium
[3] Async/Await (since ES8) => work on group of Promises + generators ... The then method attached to the Promise constructor is the...
Read more >
Async/await - The Modern JavaScript Tutorial
So, async ensures that the function returns a promise, and wraps non-promises in it. Simple enough, right? But not only that. There's another ......
Read more >
TypeScript errors and how to fix them
error TS1055: Type ' AxiosPromise ' is not a valid async function return type in ES5/ES3 because it does not refer to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found