Production build error "ShadowGeneratorSceneComponent needs to be imported"

My dev build runs fine locally but when I build for production I get the following errors:

bundle.js:11 BJS - [10:11:02]: Error running tasks-done callbacks.
bundle.js:11 ShadowGeneratorSceneComponent needs to be imported before as it contains a side-effect required by your code.

I’ve tried explicitly importing ShadowGeneratorSceneComponent and all Shadows modules but that didn’t help.

EDIT: Related Issue with babylonjs/core package and UniversalCamera

EDIT 2: When I comment out the shadow generation code, I’m now getting the same error but with LensFlareSystem i.e.

LensFlareSystemSceneComponent needs to be imported before as it contains a side-effect required by your code.

When I comment out both the ShadowGenerator and LensFlareSystem code, it builds and runs fine on production.

Problem solved.

I was using the following import statement (the form I use for everything else):

import { ShadowGeneratorSceneComponent } from "@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent";

But when I use the following import form, there are no errors and both shadow gen and lens flares work in production:

import "@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent";
import "@babylonjs/core/LensFlares/lensFlareSystemSceneComponent";

2 Likes