# FMOD craches on load on NW.js

**URL:** https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135
**Category:** FMOD Engine
**Tags:** html5
**Created:** [January 22, 2024, 7:45am UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135 "2024-01-22T07:45:01Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![skymen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skymen/32/4727_2.png) [@skymen](https://qa.fmod.com/u/skymen)
#### Post date: [January 22, 2024, 7:45am UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/1 "2024-01-22T07:45:01Z")

</div>

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;
  }
}

```

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [January 29, 2024, 12:00am UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/2 "2024-01-29T00:00:11Z")

</div>

Hi,

Thank you for sharing the solution.

What version of FMOD are you using? Could I get some reproduction steps that cause the issue?

Thanks

---

<div class="post-metadata">

### Author: ![skymen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skymen/32/4727_2.png) [@skymen](https://qa.fmod.com/u/skymen)
#### Post date: [January 29, 2024, 2:55am UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/3 "2024-01-29T02:55:26Z")

</div>

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.

Here is the build that failed:

> **[FMOD Test 1 (1).zip](https://drive.google.com/file/d/10oN0Uzu5dN-TSS77TlTdHADydVzfvQGs/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [February 2, 2024, 3:10am UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/4 "2024-02-02T03:10:52Z")

</div>

Hi,

Thank you for the project, what version of FMOD are you using?

I will pass this onto our development team to look into further, if there are any updates I will update the forum.

---

<div class="post-metadata">

### Author: ![skymen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skymen/32/4727_2.png) [@skymen](https://qa.fmod.com/u/skymen)
#### Post date: [February 4, 2024, 1:15pm UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/5 "2024-02-04T13:15:19Z")

</div>

Hi, I used FMOD v2.02.20

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [February 4, 2024, 11:40pm UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/6 "2024-02-04T23:40:09Z")

</div>

Hi,

Thank you for the information.

---

<div class="post-metadata">

### Author: ![skymen](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skymen/32/4727_2.png) [@skymen](https://qa.fmod.com/u/skymen)
#### Post date: [March 30, 2025, 6:18pm UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/7 "2025-03-30T18:18:50Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)
#### Post date: [March 30, 2025, 10:22pm UTC](https://qa.fmod.com/t/fmod-craches-on-load-on-nw-js/21135/8 "2025-03-30T22:22:44Z")

</div>

Hi,

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.
