webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

[πŸ› Bug]: Compatibility Problem with wait-port in WDIO 9 Using Node.js 20+

Open JithinJose-Mavens opened this issue 10 months ago β€’ 6 comments

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.12.7

Node.js Version

22.16.0

Mode

Standalone Mode

Which capabilities are you using?

config.capabilities = [

              {

                             'maxInstances': 1,

    browserName: 'MicrosoftEdge',

    'ms:edgeOptions': {

      args: ['--window-size=1920,1080', '--inprivate'],

    },

                             'wdio:edgedriverOptions': {

                                           binary: './msedgedriver.exe',

                             },

                             'wdio:enforceWebDriverClassic': true,

What happened?

The @wdio/cli package internally uses the wait-port module to wait for the browser driver (such as EdgeDriver) to start and listen on a specified port before initiating test execution. This ensures that the test runner does not attempt to connect to the driver before it is ready.

In WDIO version 9, the wait-port module is implemented in CommonJS (CJS) format. However, our project is using Node.js version 20+, which strictly enforces ES Module (ESM) rules. Node.js 20+ does not support importing CJS modules using the import statement when the project is configured with "type": "module" in package.json.

Due to this mismatch, WDIO fails to import the wait-port module, leading to the following error:

javascript

CopyEdit Failed to create session

TypeError: require(...) is not a function

As a result, WDIO is unable to wait for the EdgeDriver to initialize and bind to a port, causing test execution to fail during session creation.

Workaround

To overcome this issue, we downgraded the Node.js version to 18.20.3, which supports both CommonJS and ES Modules, providing better backward compatibility.

After switching to Node.js 18, the tests executed successfully, confirming that the issue is related to the incompatibility between the wait-port module’s format and the stricter ESM enforcement in Node.js 20+.

What is your expected behavior?

Session to be created

How to reproduce the bug.

Run scripts in edge browser(latest) using node 20+

Relevant log output

na

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • [x] I have searched the existing issues

JithinJose-Mavens avatar Jun 12 '25 10:06 JithinJose-Mavens

Run scripts in edge browser(latest) using node 20+

We are running Edge tests in CI using Node 20+ and they pass fine. Can you provide a simple GitHub project reproducing this problem?

christian-bromann avatar Jun 12 '25 16:06 christian-bromann

Thanks for raising this issue πŸ™

Unfortunately we can't help you without a reproducible example in this matter. Please read our contributing guidelines on how to create a reproducible example. If you can't provide a reproducible example we will close this issue in 7 days.

If you have any questions please reach out to us on our Discord channel. We are happy to help you out there.

wdio-bot avatar Jun 12 '25 16:06 wdio-bot

Hello, I'm getting the same error when trying to run a spec since today that I updated to Webdriverio 9.15.0

Here's the error:

[0-0] 2025-06-12T21:41:38.982Z ERROR @wdio/runner: TypeError: require(...) is not a function [0-0] at Object. (<project_e2e_path>\node_modules\wait-port\lib\wait-port.js:1:31) [0-0] at loadCJSModule (node:internal/modules/esm/translators:280:3) [0-0] at ModuleWrap. (node:internal/modules/esm/translators:315:7) [0-0] at ModuleJob.run (node:internal/modules/esm/module_job:222:25) [0-0] at async ModuleLoader.import (node:internal/modules/esm/loader:323:24) [0-0] at startWebDriver (<project_e2e_path>\node_modules@wdio\utils\build\index.js:508:49) [0-0] at async _WebDriver.newSession (file:///<project_e2e_path>/node_modules/webdriver/build/node.js:1334:27) [0-0] at remote (<project_e2e_path>\node_modules\webdriverio\build\node.js:8765:20) [0-0] at async Runner._startSession (file:///<project_e2e_path>/node_modules/@wdio/runner/build/index.js:815:23) [0-0] at async Runner._initSession (file:///<project_e2e_path>/node_modules/@wdio/runner/build/index.js:789:22) [0-0] node:internal/process/promises:289 [0-0] triggerUncaughtException(err, true /* fromPromise */); [0-0] ^ [0-0] [0-0] TypeError: require(...) is not a function [0-0] at Object. (<project_e2e_path>\node_modules\wait-port\lib\wait-port.js:1:31) [0-0] at loadCJSModule (node:internal/modules/esm/translators:280:3) [0-0] at ModuleWrap. (node:internal/modules/esm/translators:315:7) [0-0] at ModuleJob.run (node:internal/modules/esm/module_job:222:25) [0-0] at async ModuleLoader.import (node:internal/modules/esm/loader:323:24) [0-0] at startWebDriver (<project_e2e_path>\node_modules@wdio\utils\build\index.js:508:49) [0-0] at async _WebDriver.newSession (file:///<project_e2e_path>/node_modules/webdriver/build/node.js:1334:27) [0-0] at remote (<project_e2e_path>\node_modules\webdriverio\build\node.js:8765:20) [0-0] at async Runner._startSession (file:///<project_e2e_path>/node_modules/@wdio/runner/build/index.js:815:23) [0-0] at async Runner._initSession (file:///<project_e2e_path>/node_modules/@wdio/runner/build/index.js:789:22) [0-0] [0-0] Node.js v20.12.1

I'm using node 20.12.1 and chromedriver 137.0.3, could you please look into it?

Previously when I was using Webdriverio 9.12.7, it worked correctly, right now if I want my specs running again I have to use the workaround of downgrading to node 18.

Betusto avatar Jun 12 '25 23:06 Betusto

Previously when I was using Webdriverio 9.12.7

Can you try with the latest WebdriverIO version?

christian-bromann avatar Jun 13 '25 00:06 christian-bromann

@christian-bromann you mean 9.15.0? That's the latest version I got

Is there another WebdriverIO version?

Betusto avatar Jun 13 '25 00:06 Betusto

Yes, please try with the latest, also do you have a reproduction case?

christian-bromann avatar Jun 13 '25 00:06 christian-bromann

Closing due to inactivity. Happy to re-open once we can get a reproduction case.

christian-bromann avatar Jun 25 '25 06:06 christian-bromann