Problem loading .env texture with ES6 modules

Hi, I’m trying to load a .env file as an environment texture in a project built with ES6 NMP imported Babylon modules but I’m getting these errors and nothing is loadead:

I loaded the .env texture as in this working playground (I’m trying even with the same .env file, so I assume the problem is not withing the file itself) but it’s not working in my ES6 project:

On the other hand, it works ok if I load a .DDS texture with CubeTexture.CreateFromPrefilteredData(url, scene)

Do I need to import any special side effect module to work with the .env files?


_CleanUrl is simply:

private static _CleanUrl(url: string): string {
    url = url.replace(/#/mg, "%23");
    return url;

So, your error means url is undefined: make sure your call to load the env file is correct and that the parameters you pass are well defined.

Thanks for having a look at this issue. The url seems correct, as the .env file is placed in the same folder as the .dds and loaded the same way. The url is printed out correctly and the texture creation works with the .dds but not with the .env. In both cases I’ve used new CubeTexture(url, scene).

So, if the url is arriving as “undefined” to _CleanUrl(), it seems it’s getting lost somewhere between the initialization of the CubeTexture object and that function. But as I mentioned before, this only happens when importing the Babylon packages and tree shaking with ES6.

@sebavan may have an idea?

Did you import "@babylonjs/core/Materials/Textures/Loaders/envTextureLoader"; ???

1 Like

Heheheh. Mistery solved! Thanks guys.

I started with the ES6 tree shaking for optimizing the bundle size but I think I’ve ended up with a bigger file at the end, as I’m almost using everything :slight_smile: