Only replace slashes if the argument is defined

Fixes #2920
Merge pull request #2936 from aidanhs/aphs-fix-nodejs-no-args

Fix 'require' for emscripten modules in nodejs