Saturday, February 26, 2022

[SOLVED] Problem running same script in different platforms(Termux and Windows)

Issue

I'm trying to run my server script on nodejs through Termux on my phone and normally on windows. On windows it all runs perfectly without erros, but on termux there's an error "Cannot find module gameserver.js", even though that is the main file(I'm running "sudo node gameserver.js" inside the folder its locatedd), and no other file tries to do a require on it.

The error points to js files from node itself(loader.js, run_main.js and run_main_module.js). I've given termux root access, and I run node.js using sudo, so I've no clue what could be happening. I've no .json file since I'm just trying to run a js file through node on my phone. Both windows and my phone are using the same node.js version


Solution

Did you try to give an absolute path to your file as a parameter? It could happen if working directory has changed (because of sudo?).



Answered By - szatkus
Answer Checked By - David Goodson (WPSolving Volunteer)