Skip to content

[BUG] _interopRequireWildcard not defined in browser when using "import()" in page.evaluate() #23255

@Ademsk1

Description

@Ademsk1

System info

  • Playwright Version: [v1.34.0]
  • Operating System: [macOS 13.2]
  • Browser: [All]
  • Other info:
    Trying to import a url module in page.evaluate raises the following error:
    Error: page.evaluate: ReferenceError: _interopRequireWildcard is not defined
    despite me only using the following:
page.evaluate(()=> {
const {getAuth} = import('some-url-link-to-module')
}

I found this strange, as I don't use _interopRequireWildcard at all. When in the debugging browser session, I plugged my commands in manually, and had no issues at all. On further inspection within the evaluate function, it seems as though the command import(...) gets converted into:

await Promise.resolve().then(() => _interopRequireWildcard(require('some-url-link-to-module')));

within the pageFunction variable in page.evaluate. I decided to quickly try and change it back to its regular import(...) and it worked! However, even if _interopRequireWildcard was defined in the browser, require wouldn't be, and so if this could be altered so that import() doesn't get modified, this would work.

Steps

  • Run a test with page.evaluate(...) where within it we use the import() method to import a url module

Expected
Module should be imported and usable

Actual
Error occurs due to some action causing import() to be rewritten as a promise that uses _interopRequireWildcard

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions