-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
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-pkg → unicorn-magic during startup.
Root Cause
- WDIO 9 uses
tsxto run TypeScript config files (.tsfiles) - The WDIO worker process that runs the config inherits
NODE_OPTIONSwith thetsxloader @wdio/appium-servicespawns the Appium process usingspawn()without a customenv, so the child process inherits the parent'sprocess.env(includingNODE_OPTIONSwithtsx)- When Appium loads
read-pkg→unicorn-magic,tsx's resolver interferes with Node's native package exports resolution, causing theERR_PACKAGE_PATH_NOT_EXPORTEDerror
Environment
- @wdio/appium-service:
9.23.2 - webdriverio:
9.23.2 - appium:
3.2.0 - Node.js:
20.20.0(also tested with24.13.0) - TypeScript config: Yes (using
wdio.config.ts) - unicorn-magic:
0.4.0(via resolutions; issue also occurs with0.3.0)
Reproduction Steps
- Create a WDIO project with TypeScript config (
wdio.config.ts) - Add
@wdio/appium-serviceto the services array - Run
yarn test(orwdio run wdio.config.ts) - The Appium process fails during the
onPreparehook
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 runningyarn testdoesn'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-pkg → unicorn-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.