Some solved problems while treeshaking

Hi.
I was trying treeshaking today according to this doc and met some errors in the console. Yet I found ways to solve them.

while the doc itself haven’t listed such bugs, here I post them and the solutions here because I think they might be very common.

import { Engine } from "@babylonjs/core/Engines/engine"; 
// would cause engine to miss RegisterView method. SOLUTION:
import { Engine } from "@babylonjs/core/Engines/engine"; 
import "@babylonjs/core/Engines/Extensions/engine.views";
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
// console error "need to import shadowGeneratorSceneComponent" or something. SOLUTION:
import '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent';
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
import { NodeMaterial } from '@babylonjs/core/Materials/Node/nodeMaterial';
// console error "XXX block is missing input YYY and is necessary". SOLUTION:
import { NodeMaterial } from '@babylonjs/core/Materials/Node';

// and I found another solution:
import { NodeMaterial } from '@babylonjs/core/Materials/Node/nodeMaterial';
import '@babylonjs/core/Materials/Node/Blocks';
2 Likes

The First one should be the following I believe:

import { Engine } from "@babylonjs/core/Engines/engine"; 
import "@babylonjs/core/Engines/Extensions/engine.views";

About the third your solution will do all the nodes but you might as well limit to only the node you use :slight_smile:

thank you, I edited your answer into the first solution.

for the third one, if I only import NodeMaterial from .../Materials/Node/nodeMaterial, it throws an error like this:

Build of NodeMaterial failed:
input rgba from block FragmentOutput[FragmentOutputBlock] is not connected and is not optional.

update

well I looked into the Materials/Node/Index.js and tried each of the import, the missing part I needed is Materials/Node/Blocks, I’ll edit into the main post :slight_smile: