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:
I am using the latest fmodStudio wasm version (not large, although I suppose it would also happen with large) and I exported using the NW.js export from the Construct 3 engine.
Hi, this issue still happens on the latest version of FMOD
For some reason the code in the library now is:
var ENVIRONMENT_IS_NODE =
typeof process == “object” &&
typeof process.versions == “object” &&
typeof process.versions.node == “string”;
if (ENVIRONMENT_IS_NODE) {
}
instead of
var 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;
}
}
I assume you must have something in your build system that removes tryCatch blocks?
Unfortunately, the task is still in our backlog. So if you have updated the integration the workaround will have to be reapplied. I will bump that task.