FMOD crashes on load on NW.js because it detects NW.js as a “Node Environment” and assumes __dirname exists but it appears that it does not in NW.js
Maybe it can be replaced with “process.cwd()” I suppose.
In general, I think it’s a good idea to at least do a tryCatch on the environment detection code and fallback to non Node environment in case it did not work out.
Here is the error:
ReferenceError: __dirname is not defined
And here is the code concerned by this:
if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require(“path”).dirname(scriptDirectory) + “/”;
} else {
scriptDirectory = __dirname + “/”;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
Here is my code that seems to have fixed the issue:
ENVIRONMENT_IS_NODE =
typeof process === "object" &&
typeof process.versions === "object" &&
typeof process.versions.node === "string";
if (ENVIRONMENT_IS_NODE) {
try {
if (__dirname === undefined) ENVIRONMENT_IS_NODE = false;
} catch (error) {
ENVIRONMENT_IS_NODE = false;
}
}