I’m using VueJS 3 and the Vite development/build tool (fairly new, based on rollup, see GitHub - vitejs/vite: Native-ESM powered web dev build tool. It's fast.). So far, things are working, but I can’t seem to get access to the procedural textures (fire, wood, etc.). Attempting to instantiate these leads to an error like this:
Uncaught (in promise) TypeError: BABYLON.FireProceduralTexture is not a constructor
at initBabylon (App.vue:35)
at App.vue:82
I’ve done the npm install
and the import 'babylonjs-procedural-textures';
as described in the docs (babylonjs-procedural-textures - npm), but the new textures have not been added to the BABYLON
namespace.
I’ve also messed around with trying to import and reference the classes more specifically from that npm library, but that just leads to “not a constructor” errors.
Here’s a minimal reproducible example of the issue. npm install
, then npm run devs
(the “s” is for https in this case) and check the console:
I have a sense that this is some weird issue dealing with ES modules, but it’s over my head…
Note the reference in the vue.config.js
file to babylonjs-procedural-textures
. This is because when I didn’t have that configuration piece set up, I got the following warning from Vite while it was running. Now I don’t get the warning, but I still can’t use the textures.
[vite] Avoid deep import "babylonjs-procedural-textures/babylonjs.proceduralTextures" (imported by /src/App.vue) because "babylonjs-procedural-textures" has been pre-optimized by vite into a single file. Prefer importing directly from the module entry:
import { ... } from "babylonjs-procedural-textures"
If the dependency requires deep import to function properly, add the deep path to optimizeDeps.include in vite.config.js.
It’s possible this is a problem with Vite. If so, I’m happy to add and Issue over there, but I’m hoping at least someone here will understand better what the issue is and whether there is a viable workaround.