# Cannot load gltf model in a module-type Web Worker due to \`importScripts\` dependency

**URL:** <https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764>\
**Category:** Bugs\
**Tags:** workers\
**Created:** [March 12, 2026, 9:12pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764 "2026-03-12T21:12:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_FrameVR](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/will_framevr/32/48897_2.png) [@Will\_FrameVR](https://forum.babylonjs.com/u/Will_FrameVR)\
**Post date:** [March 12, 2026, 9:12pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/1 "2026-03-12T21:12:06Z")

</div>

Repro: [Babylon.js Playground](https://playground.babylonjs.com/#X0E7M1)

We’re in the process of converting a project from Webpack to Vite, and one blocker is with our use of NullEngine in Web Workers to load compressed GLBs and generate navmeshes.

With Vite, workers are created as es modules, and module-type workers do not have access to `importScripts`. If you try to use SceneLoader to import a meshopt-compressed GLTF, it will trigger a call to `importScripts` in `_LoadScriptWeb` from `core/src/Misc/tools.ts` and error.

I’ll be sending a PR

---

<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:** [March 12, 2026, 10:03pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/2 "2026-03-12T22:03:48Z")

</div>

Thanks a lot for the contrib !!! 🙂

---

<div class="post-metadata">

**Author:** ![regna](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/regna/32/23915_2.png) [@regna](https://forum.babylonjs.com/u/regna)\
**Post date:** [March 13, 2026, 6:32am UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/3 "2026-03-13T06:32:07Z")

</div>

Amazing, thank you!!

---

<div class="post-metadata">

**Author:** ![Will\_FrameVR](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/will_framevr/32/48897_2.png) [@Will\_FrameVR](https://forum.babylonjs.com/u/Will_FrameVR)\
**Post date:** [March 13, 2026, 1:39pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/4 "2026-03-13T13:39:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/8/c8340b8e22f76c613d7b8555fdc8c8f08510698e.png)

@sebavan I have to use the async `import()`, but `_LoadScriptWeb` is not currently async and I see this lint rule forbidding `.then()`. Would you prefer I change `_LoadScriptWeb` to be async (it has no return value, so should be safe) or use an async iife here?

---

<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:** [March 13, 2026, 1:52pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/5 "2026-03-13T13:52:27Z")

</div>

I think in this particular case we should use the .then and .catch as it matches with some Babylon Native API with a linter disable bypass and a comment

---

<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:** [March 13, 2026, 1:52pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/6 "2026-03-13T13:52:38Z")

</div>

cc @bghgary

---

<div class="post-metadata">

**Author:** ![Will\_FrameVR](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/will_framevr/32/48897_2.png) [@Will\_FrameVR](https://forum.babylonjs.com/u/Will_FrameVR)\
**Post date:** [March 13, 2026, 3:32pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/7 "2026-03-13T15:32:22Z")

</div>

@sebavan thanks for the help - one more question:

When testing backwards compatibility, I see the proposed new code causes this warning to be printed in webpack builds:

```auto
WARNING in ../node_modules/@babylonjs/core/Misc/tools.js 450:20-37
Critical dependency: the request of a dependency is an expression
 @ ./mainline/babylon.ts 68:0-51 70:0-19 71:0-18
 @ ./mainline/index.js 10:0-42 45:26-43

```

It is webpack reporting that the new `import()` can’t be statically analyzed for dependencies. This is fine, of cource, because the load script utils are only ever used to import external sources. I can add a **`/* webpackIgnore: true */`** comment here to explicitly mark it as an external dependency and squash the warning, but I’m not sure if you want bundler-specific directives in the source

---

<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:** [March 13, 2026, 3:44pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/8 "2026-03-13T15:44:37Z")

</div>

Looks like a @ryantrem question 🙂

---

<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:** [March 13, 2026, 5:26pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/9 "2026-03-13T17:26:21Z")

</div>



---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [March 13, 2026, 9:04pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/10 "2026-03-13T21:04:26Z")

</div>

A few thoughts:

- I think fully using async/await would be best, but to reduce risk close to the 9.0 release, I think keeping .then/.catch with eslint suppressions is fine.
- I think falling back to `import` in the catch also seems fine to deal with module workers.
- My preference would be to avoid bundler specific directives, and I think it can be done with something like:

```ts
const dynamicImport = new Function("url", "return import(url)");
dynamicImport(scriptUrl).then(...).catch(...);

```

That said, I see we recently used `import` with a webpack directive just like this in another place. @RaananW do you have an opinion?

---

<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:** [March 16, 2026, 4:11pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/11 "2026-03-16T16:11:06Z")

</div>

Good question 🙂

We have **`/* webpackIgnore */`** only in tools (i.e. - playground and the experimental snippet loader), mostly becasue we are the ones packing them. The framework itself should not have any bundler-specific code IMO.

---

<div class="post-metadata">

**Author:** ![Will\_FrameVR](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/will_framevr/32/48897_2.png) [@Will\_FrameVR](https://forum.babylonjs.com/u/Will_FrameVR)\
**Post date:** [March 17, 2026, 1:14pm UTC](https://forum.babylonjs.com/t/cannot-load-gltf-model-in-a-module-type-web-worker-due-to-importscripts-dependency/62764/12 "2026-03-17T13:14:56Z")

</div>

Thanks everyone. I’ll send it up with the Function constructor workaround and the eslint disable comment
