# IsWindowObjectExist is not a function - ES6 support with Tree Shaking - bug?

**URL:** <https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583>\
**Category:** Questions\
**Created:** [July 20, 2023, 3:05pm UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583 "2023-07-20T15:05:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxim\_Sheronov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/maxim_sheronov/32/33778_2.png) [@Maxim\_Sheronov](https://forum.babylonjs.com/u/Maxim_Sheronov)\
**Post date:** [July 20, 2023, 3:05pm UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/1 "2023-07-20T15:05:30Z")

</div>

Hi there!

I use babylon 6.11 with es6 support. Parcel is for running and building.  
Everything worked, but when I try to run a production build, I got an error:

TypeError: e\_.IsWindowObjectExist is not a function  
 ![изображение](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/6/e6e27243dfc0a43cf9bf939f62d8a8a68c75e6cf.png)  
it’s coming from engine creation here  
 ![изображение](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/5/65902f4343490e42aeea9ae2e401920e51e0e799.png)

I thought that I need to import something, but not. IsWindowObjectExist is defined, but it is not a function. So if I look in that source file domManagement.ts, I will see export function  
 ![изображение](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/f/9f1fdb7a97dbd9f3e89474c77986861f788b498e.png)

and export DomManagement like this  
 ![изображение](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/3/03d5aac1d2f63ec1d36578aef1e2667f43de284d.png)

And I am not so expert in js/ts to understand what is problem. But it is here.

Because when I try to use that function by two ways, one is working, and another gives same error:

 ![изображение](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/9/b9f14fadfb4eed724861e8f253b6f2527319597c.png)

And I don’t know what to do with it. I use parcel to serve and develop, it’s working fine. But when I build in production mode, I get that error. Maybe in dev mode process of engine creation is different and that is a bug. Maybe something else. Hope somebody can help 🙂

P.S.  
In dev mode both functions gives “true”. So maybe problem is in Tree Shaking process. But how to fix it?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [July 20, 2023, 8:14pm UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/2 "2023-07-20T20:14:05Z")

</div>

This is so weird knowing how DomManagement is exported:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/1/a134f4957b593c35d8e0fec987a359adf496a344.png)

@RaananW might have a clue ?

---

<div class="post-metadata">

**Author:** ![Maxim\_Sheronov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/maxim_sheronov/32/33778_2.png) [@Maxim\_Sheronov](https://forum.babylonjs.com/u/Maxim_Sheronov)\
**Post date:** [July 21, 2023, 7:06am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/3 "2023-07-21T07:06:31Z")

</div>

I tried to migrate to Webpack, and it is working. And then migrated to Vite (because it’s easy to configurate, as Parcel), and Vite is working too. I mean production builds, made with Webpack and Vite, both working.

So it looks like some problem on Parcel side. But anyway, it’s weird.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 21, 2023, 9:38am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/4 "2023-07-21T09:38:35Z")

</div>

because I love finding out why those things happen - would you be able to share a simple parcel configuration that fails? that would be a great help 🙂

---

<div class="post-metadata">

**Author:** ![Maxim\_Sheronov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/maxim_sheronov/32/33778_2.png) [@Maxim\_Sheronov](https://forum.babylonjs.com/u/Maxim_Sheronov)\
**Post date:** [July 21, 2023, 10:35am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/5 "2023-07-21T10:35:21Z")

</div>

Sure. This is small repro project.  
I cannot attach a file, so made a repo on github.

> **[GitHub - maxim-sheronov/babylon-parcel-bug-repro-project](https://github.com/maxim-sheronov/babylon-parcel-bug-repro-project)**
>
> Contribute to maxim-sheronov/babylon-parcel-bug-repro-project development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 21, 2023, 10:38am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/6 "2023-07-21T10:38:49Z")

</div>

you’re the best, thanks! I’ll make sure to analyze this.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 21, 2023, 10:38am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/7 "2023-07-21T10:38:52Z")

</div>



---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 24, 2023, 1:47pm UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/8 "2023-07-24T13:47:02Z")

</div>

ok, it does seem like Parcel doesn’t like const objects holding functions. the production build is over-optimizing the build and removes functions that are not directly referenced in your code.

One solution is to import the DomManagement directly and actually using it once. Something like this is enough:

```auto
import { DomManagement } from "@babylonjs/core/Misc/domManagement";
console.log(DomManagement)

```

That presents a new interesting issue - MeshBuilder has the same issue :-). So you should instead import the CreateGround directly from the groundBuilder:

`import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";`

So if main .ts looks like this:

```javascript
import { engine, scene } from './scene'
import { DomManagement } from "@babylonjs/core/Misc/domManagement";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
import "@babylonjs/core/Materials/standardMaterial";

console.log(DomManagement)

async function main(): Promise<void> {
    CreateGround(
        'ground',
        { width: 4, height: 4 },
        scene
    )

    engine.runRenderLoop(() => {
        scene.render()
    })
}

main();

```

It compiles correctly in prod mode.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [July 24, 2023, 1:47pm UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/9 "2023-07-24T13:47:06Z")

</div>



---

<div class="post-metadata">

**Author:** ![Maxim\_Sheronov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/maxim_sheronov/32/33778_2.png) [@Maxim\_Sheronov](https://forum.babylonjs.com/u/Maxim_Sheronov)\
**Post date:** [July 25, 2023, 8:54am UTC](https://forum.babylonjs.com/t/iswindowobjectexist-is-not-a-function-es6-support-with-tree-shaking-bug/42583/10 "2023-07-25T08:54:44Z")

</div>

Good to know! Thanks.  
I will stay with Vite. But it can be helpfull for somebody in future.
