Can't find main.js /appium folder

Hello. So I recently switched from the appium GUI to the appium npm version.
I installed it with the npm install -g appium command, and I’m able to run the “appium &” command in the terminal to start the server and run my tests, so everything seems fine.

Until the point I try to start my server programatically I find a problem, I can’t find the appium.app folder and the main.js file I need in my appiumserver constructor to start the server. What am I doing wrong?
I found a similar thread Unable to launch appium programatically on mac due to missing file appium.js in "Appium.app/Contents/Resources/node_modules/appium/bin/"
But can’t understand how they solved their problem.

Appreciate all help loads, regards.
Im using OSX

run command “which appium” on your terminal , It will show you the path it got installed

Please uninstall once and download again with npm only .
then enter node -v in the command prompt
u will get version number that u have installed if u r getting ryt then move forward nd give the path of ur apk in android setting and then run the node.
It will start successfully …

Hello.

Thanks for your help.
I used this command and found my appium folder (it was in “/usr/local/lib/node_modules/appium)
I try start my server with
AppiumServer _appiumServer = new AppiumServer(new File(”/usr/local/lib/node_modules/npm/bin/npm-cli.js"),new File("/usr/local/lib/node_modules/appium/lib/main.js"),serverArguments);

_appiumServer.startServer();

But I now I get this message
aug 11, 2017 2:24:29 EM com.github.genium_framework.appium.support.server.AppiumServer startServer INFO: Server is starting... aug 11, 2017 2:24:29 EM com.github.genium_framework.appium.support.server.AppiumServer startServer INFO: Server has not started yet. Trying again in one second...

This continues until I get ServerTimeoutException, any ideas how I can fix this problem?
Regards rickesnick

you may try using AppiumServiceBuilder

AppiumServiceBuilder builder = new AppiumServiceBuilder()
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withArgument(GeneralServerFlag.APP, path of your app );
appiumDriverLocalService = builder.build();
appiumDriverLocalService.start();

1 Like

Thanks. Solved this issue by doing the following things
Using AppiumDriverLocalService

service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File(“/usr/local/bin/node”))
.withAppiumJS(
new File(
“/usr/local/lib/node_modules/appium/build/lib/main.js”))
.withIPAddress(“127.0.0.1”).usingPort(4723));
service.start();

2 Likes

Hey, I`m new to Appium.
I have a question: on windows, where should I point this file to?
I see it is “/usr/local/lib/node_modules/appium/build/lib/main.js” for linux.
Maybe it is a stupid question, but if I want to start the service with AppiumServiceBuilder, should I install appium before that? I want to integrate Appium in a Java project and I’m not sure if I should provide installation support for the client or it is working directly with AppiumServiceBuilder.
Thank you!

install it first by cmd entring command = npm install -g appium

you will find main.js here :

C:Users/admin/AppData/Roaming/npm/node_modules/appium/build/lib/main.js";

1 Like

Thank you, Chetan! I really appreciate it!

1 Like

I used this code and when I run it now, I’m getting this error, even though I have set the path for ANDROID_HOME

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported.

as i enter cmd appium

i am getting this error please give solutin

@seo try doing Run as > Run configuration > add env path one by one, both JAVA_HOME & ANDROID_HOME(you can get by echo command).

@adit try running appium -doctor and check for the errors.

@Aleksei @wreed
I am facing the same/similar issue.
Previously when I try to run appium server programmatically, node.js could not be found. So apart from node.js being installed by nvm, I additionally installed the same node.js from nodes.org web site and gave it’s path in the .zshrc, my profile file. Now a new error similar to the above is coming up:

*io.appium.java_client.service.local.InvalidServerInstanceException: The main Appium script does not exist at '~/<project installation folder>/appium/build/lib/main.js'*

When I run ‘appium-doctor’ it is reporting Diagnostic for necessary dependencies completed, no fix needed

When I run ‘which appium’ on the terminal, I get the path “~/.nvm/versions/node/v18.12.0/bin/appium”. I don’t understand why appium goes and installs under one of the node versions installed via nvm ???

As per my understanding, it should properly reside at ‘/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/main.js’.

Instead the appium.js file does exist at two places ~/node_modules/appium/build/lib and ~/node_modules/appium/lib

When I run ‘appium’ at the terminal, it’s output is

[Appium] Welcome to Appium v2.0.0-beta.57 (REV 4b947ec92d0195756709e5b563569cf48aef1e09)
[Appium] Attempting to load driver xcuitest…
[debug] [Appium] Requiring driver at /Users/venkatanutalapati/.appium/node_modules/appium-xcuitest-driver
[Appium] Attempting to load driver uiautomator2…
[debug] [Appium] Requiring driver at /Users/venkatanutalapati/.appium/node_modules/appium-uiautomator2-driver
[Appium] Attempting to load driver flutter…
[debug] [Appium] Requiring driver at /Users/venkatanutalapati/.appium/node_modules/appium-flutter-driver
[Appium] Attempting to load driver safari…
[debug] [Appium] Requiring driver at /Users/venkatanutalapati/.appium/node_modules/appium-safari-driver
[Appium] Attempting to load driver gecko…
[debug] [Appium] Requiring driver at /Users/venkatanutalapati/.appium/node_modules/appium-geckodriver
(node:29873) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[Appium] Available drivers:
[Appium] - [email protected] (automationName ‘XCUITest’)
[Appium] - [email protected] (automationName ‘UiAutomator2’)
[Appium] - [email protected] (automationName ‘Flutter’)
[Appium] - [email protected] (automationName ‘Safari’)
[Appium] - [email protected] (automationName ‘Gecko’)

Please help me correct the errors and run the appium programmatically.

You can main.js path

from: //usr//local//lib//node_modules//appium//build//lib//main.js

to: //opt/homebrew/lib/node_modules/appium//build//lib//main.js

to check your appium batch use

which appium

command on the terminal to find the appium path then you can path before to the appium folder alone