Skip to content

[🐛 Bug]: Appium process fails with ERR_PACKAGE_PATH_NOT_EXPORTED when spawned by @wdio/appium-service #15062

@italocsn05

Description

@italocsn05

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @wdio/appium-service@9.23.2 for the project I'm working on.

Problem Description

When @wdio/appium-service spawns the Appium process, it fails with the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/unicorn-magic/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:322:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:613:13)
    ...
    at fs (/Users/.../node_modules/read-pkg/index.js:6:22)
    at Object.<anonymous> (/Users/.../node_modules/read-pkg/index.js:32:17)

The error occurs during the onPrepare hook when Appium tries to load read-pkgunicorn-magic during startup.

Root Cause

  1. WDIO 9 uses tsx to run TypeScript config files (.ts files)
  2. The WDIO worker process that runs the config inherits NODE_OPTIONS with the tsx loader
  3. @wdio/appium-service spawns the Appium process using spawn() without a custom env, so the child process inherits the parent's process.env (including NODE_OPTIONS with tsx)
  4. When Appium loads read-pkgunicorn-magic, tsx's resolver interferes with Node's native package exports resolution, causing the ERR_PACKAGE_PATH_NOT_EXPORTED error

Environment

  • @wdio/appium-service: 9.23.2
  • webdriverio: 9.23.2
  • appium: 3.2.0
  • Node.js: 20.20.0 (also tested with 24.13.0)
  • TypeScript config: Yes (using wdio.config.ts)
  • unicorn-magic: 0.4.0 (via resolutions; issue also occurs with 0.3.0)

Reproduction Steps

  1. Create a WDIO project with TypeScript config (wdio.config.ts)
  2. Add @wdio/appium-service to the services array
  3. Run yarn test (or wdio run wdio.config.ts)
  4. The Appium process fails during the onPrepare hook

Workaround Verification

  • ✅ Running Appium manually (npx appium --base-path / --port 4723) works perfectly
  • ✅ The issue only occurs when Appium is spawned by @wdio/appium-service
  • ✅ Setting NODE_OPTIONS="" in the shell before running yarn test doesn't help, because WDIO sets it internally when running TypeScript configs

Solution

The fix is to spawn the Appium process with a clean NODE_OPTIONS environment variable, preventing it from inheriting the tsx loader from the parent process. This allows Appium to use Node's native module resolution instead of tsx's resolver.

Here is the diff that solved my problem:

diff --git a/node_modules/@wdio/appium-service/build/index.js b/node_modules/@wdio/appium-service/build/index.js
index 4248b45..a7a23af 100644
--- a/node_modules/@wdio/appium-service/build/index.js
+++ b/node_modules/@wdio/appium-service/build/index.js
@@ -190,7 +190,8 @@ var AppiumLauncher = class _AppiumLauncher {
   }
   _startAppium(command, args, timeout = APPIUM_START_TIMEOUT) {
     log.info(`Will spawn Appium process: ${command} ${args.join(" ")}`);
-    const appiumProcess = spawn(command, args, { stdio: ["ignore", "pipe", "pipe"] });
+    const appiumEnv = { ...process.env, NODE_OPTIONS: "" };
+    const appiumProcess = spawn(command, args, { stdio: ["ignore", "pipe", "pipe"], env: appiumEnv });
     let errorCaptured = false;
     let timeoutId;
     let error;

Expected Behavior

The Appium process should be spawned without inheriting NODE_OPTIONS from the parent process, allowing it to use Node's native module resolution instead of tsx's resolver. This would prevent the ERR_PACKAGE_PATH_NOT_EXPORTED error when Appium loads dependencies like read-pkgunicorn-magic.

Suggested Fix Location

File: packages/wdio-appium-service/src/launcher.ts (or build/index.js)
Method: _startAppium()

The fix ensures that the Appium child process runs with a clean environment, specifically clearing NODE_OPTIONS to avoid inheriting the tsx loader from the parent WDIO worker process.


This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions