# Getting Unable to connect to "http://localhost:4723/wd/hub" error with node 18 when run against mobile Apps

**URL:** <https://discuss.appium.io/t/getting-unable-to-connect-to-http-localhost-4723-wd-hub-error-with-node-18-when-run-against-mobile-apps/42854>\
**Category:** Issues/Bugs\
**Created:** [June 20, 2024, 5:06pm UTC](https://discuss.appium.io/t/getting-unable-to-connect-to-http-localhost-4723-wd-hub-error-with-node-18-when-run-against-mobile-apps/42854 "2024-06-20T17:06:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aduait\_Pokhriyal](https://discuss.appium.io/user_avatar/discuss.appium.io/aduait_pokhriyal/32/13227_2.png) [@Aduait\_Pokhriyal](https://discuss.appium.io/u/Aduait_Pokhriyal)\
**Post date:** [June 20, 2024, 5:06pm UTC](https://discuss.appium.io/t/getting-unable-to-connect-to-http-localhost-4723-wd-hub-error-with-node-18-when-run-against-mobile-apps/42854/1 "2024-06-20T17:06:50Z")

</div>

I have webdriverio + cucumberjs based tests and When using node 18, I,m getting error - `http://localhost:4723/wd/hub`  
Setup:

```auto
node v18.20.3 (npm v10.7.0)
appium@2.8.0
xcuitest@5.8.1

```

I am able to run against iOS safari browser but fails to runs against any mobile App. But my same tests works when I use node 16.

```auto
node v16.20.2 (npm v8.19.4)
appium@2.8.0
xcuitest@5.8.1

```

Error log:

```auto
Unable to connect to "http://localhost:4723/wd/hub", make sure browser driver is running on that address.
If you use services like chromedriver see initialiseServices logs above or in wdio.log file as the service might had problems to start the driver.
    at Runtime.runTestRunHooks (/private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/@cucumber/cucumber/lib/runtime/run_test_run_hooks.js:23:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Runtime.start (/private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/@cucumber/cucumber/lib/runtime/index.js:53:9)
    at async runCucumber (/private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/@cucumber/cucumber/lib/api/run_cucumber.js:106:21) {
  jse_shortmsg: 'a BeforeAll hook errored, process exiting: node_modules/<my-package>/dist/myfile.js:72',
  jse_cause: Error: Failed to create session.
  Unable to connect to "http://localhost:4723/wd/hub", make sure browser driver is running on that address.
  If you use services like chromedriver see initialiseServices logs above or in wdio.log file as the service might had problems to start the driver.
      at startWebDriverSession (file:///private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/webdriver/build/utils.js:68:15)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async WebDriver.newSession (file:///private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/webdriver/build/index.js:26:45)
      at async remote (file:///private/tmp/scratchEmNi2G.scratch/test-packagesbz9OA/node_modules/<my-package>/node_modules/webdriverio/build/index.js:48:22),
  jse_info: {},
  cause: [Function: ve_cause]

```

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [June 20, 2024, 6:16pm UTC](https://discuss.appium.io/t/getting-unable-to-connect-to-http-localhost-4723-wd-hub-error-with-node-18-when-run-against-mobile-apps/42854/2 "2024-06-20T18:16:47Z")

</div>

Might be this:

> <https://github.com/webdriverio/webdriverio/issues/8760>
>
> \### Have you read the Contributing Guidelines on issues?
> 
> \- \[X\] I have read the …\[Contributing Guidelines on issues\](https://github.com/webdriverio/webdriverio/blob/main/CONTRIBUTING.md#reporting-new-issues).
> 
> \### WebdriverIO Version
> 
> ^7.23.0
> 
> \### Node.js Version
> 
> 18.7.0
> 
> \### Mode
> 
> WDIO Testrunner
> 
> \### Which capabilities are you using?
> 
> \`\`\`typescript
> {
> specs: \['./e2e/specs/\*\*/\*.spec.js' \],
> reporters: \['spec' \],
> capabilities: \[
> {
> 'appium:platformVersion': '15.5',
> 'appium:deviceName': 'iPhone Simulator',
> browserName: 'Safari',
> platformName: 'iOS'
> }
> \],
> services: \[\[ 'appium' \] \],
> maxInstances: 1,
> execArgv: \[\],
> sync: false,
> deprecationWarnings: true,
> waitforTimeout: 15000,
> connectionRetryTimeout: 240000,
> connectionRetryCount: 1,
> framework: 'jasmine',
> runner: 'local',
> port: 4723,
> baseUrl: 'http://0.0.0.0:4000/',
> suites: { home: \['./e2e/specs/home.spec.js' \] },
> }
> \`\`\`
> 
> 
> \### What happened?
> 
> Using node v16, this works as expected: \`WDIO\_LOG\_PATH=wdio.log WDIO\_DEBUG=trace wdio --suite home\`. The ios simulator boots up, loads up safari, loads the website running locally and passes the tests.
> 
> Using node v18, the same command does not work. It fails to launch the ios simulator. I can go between node v16 and v18 for chrome driver, safari driver as expected, this is isolated to appium as a service as listed above.
> 
> I traced the error down to the the webdriver package, specifically request/factory which returns a NodeJSRequest. From here I'm not sure if its the implemented \_libRequest that relies on got that is the issue or an unpredictable behavior with EventEmitter in node v18.
> 
> When makeRequest is called by the startWebDriverSession from utils, its either an issue with the call to this.emit('request') or afterwards when making call to this.\_request which ends up making a call to the \_libRequest from NodeJSRequest.
> 
> I feel like it is related to the EventEmitter either from this library or got's, something could of changed with node 18, as it usually does. I also tried using node v18.2.0 with same result. Its also entirely possible since we're not using esm module type this could be it too. I say this because when i run yarn why got, it shows as got@11.8.5 and neglects to use the version of got as seen in the webdriver/package.json of ^12.1.0. should we be using wedriver@next or is it possible the regular tag releases aren't getting the updates from main?
> 
> i dont expect this to get fixed as its pretty low level and can i can get around by using node v16 instead. wanted to report it in case anyone else came across the same thing and started pulling their hair out.
> 
> \### What is your expected behavior?
> 
> \_No response\_
> 
> \### How to reproduce the bug.
> 
> use node 18 and run \`WDIO\_LOG\_PATH=wdio.log WDIO\_DEBUG=trace wdio --suite home\` with the above wdio.conf.js
> 
> \### Relevant log output
> 
> \`\`\`typescript
> dont pay attention to the logs, they are not indicative of the issue as the result from the appium not starting earlier up the call stack
> 
> \[0-0\] at ClientRequest.\<anonymous\> (./node\_modules/got/dist/source/core/index.js:970:111)
> \[0-0\] at Object.onceWrapper (node:events:642:26)
> \[0-0\] at ClientRequest.emit (node:events:539:35)
> \[0-0\] at ClientRequest.emit (node:domain:475:12)
> \[0-0\] at ClientRequest.origin.emit (./node\_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
> \[0-0\] at Socket.socketErrorListener (node:\_http\_client:454:9)
> \[0-0\] at Socket.emit (node:events:527:28)
> \[0-0\] at Socket.emit (node:domain:475:12)
> \[0-0\] at emitErrorNT (node:internal/streams/destroy:151:8)
> \[0-0\] at emitErrorCloseNT (node:internal/streams/destroy:116:3)
> \[0-0\] at TCPConnectWrap.afterConnect \[as oncomplete\] (node:net:1195:16)
> \`\`\`
> 
> 
> \### 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

What version webdriverio?

---

<div class="post-metadata">

**Author:** ![Aduait\_Pokhriyal](https://discuss.appium.io/user_avatar/discuss.appium.io/aduait_pokhriyal/32/13227_2.png) [@Aduait\_Pokhriyal](https://discuss.appium.io/u/Aduait_Pokhriyal)\
**Post date:** [November 20, 2024, 6:36pm UTC](https://discuss.appium.io/t/getting-unable-to-connect-to-http-localhost-4723-wd-hub-error-with-node-18-when-run-against-mobile-apps/42854/3 "2024-11-20T18:36:56Z")

</div>

Yes, it was related. I had to change hostname from `localhost` to `127.0.0.1` . (More info: [webdriverio/webdriverio#8763](https://github.com/webdriverio/webdriverio/pull/8763))
