Cannot find module 'babylonjs/Meshes'

When trying to update babylonjs version 5.35.1 I get typescript compilation errors in babylonjs code starting with version 5.36.0. For version 5.50.1 the error message is:

node_modules/babylonjs/babylon.module.d.ts:87508:45 - error TS2307: Cannot find module ‘babylonjs/Meshes’ or its corresponding type declarations.

87508 import { TransformNode, AbstractMesh } from “babylonjs/Meshes”;
~~~~~~~~~~~~~~~~~~

If I change the line to:

import { TransformNode } from “babylonjs/Meshes/transformNode”
import { AbstractMesh } from “babylonjs/Meshes/abstractMesh”

everything is fine again.

Welcome to the Babylon community
We’ve had some typescript version changes recently, @RaananW will know if it’s related.

let me check that :slight_smile:

Thanks for reporting

Will be fixed shortly - Import fix for UMD modules typing by RaananW · Pull Request #13624 · BabylonJS/Babylon.js (github.com)
Thanks again :slight_smile:

2 Likes

I also have this similar kind of error on version 6.36.0:

 Typecheck started…
node_modules/babylonjs/babylon.module.d.ts(28482,28): error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.
node_modules/babylonjs/babylon.module.d.ts(28501,28): error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.
node_modules/babylonjs/babylon.module.d.ts(28570,28): error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.
node_modules/babylonjs/babylon.module.d.ts(71612,46): error TS2307: Cannot find module 'babylonjs/Meshes' or its corresponding type declarations.
node_modules/babylonjs/babylon.module.d.ts(71722,46): error TS2307: Cannot find module 'babylonjs/Meshes' or its corresponding type declarations.

✖  Typecheck failed with 5 errors
ℹ  Typecheck finished in 1741ms

Here is tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "ESNext",
    "moduleResolution": "node",
    "noResolve": false,
    "noImplicitAny": false,
    "sourceMap": true,
    "preserveConstEnums":true,
    "lib": [
        "dom",
        "es2020"
    ]
  }
}

Here is my package json:

...
 "dependencies": {
    "babylonjs": "^6.36.0",
    "babylonjs-gui": "^6.36.0",
    "babylonjs-materials": "^6.36.0",
}

Here is the typescript code:


import * as BABYLON from "babylonjs";
import * as MAT from "babylonjs-materials";
class App {
    constructor() {
        // create the canvas html element and attach it to the webpage
        var canvas = document.createElement("canvas");
        canvas.style.width = "100%";
        canvas.style.height = "100%";
        canvas.id = "gameCanvas";
        document.body.appendChild(canvas);

        // initialize babylon scene and engine
        var engine = new BABYLON.Engine(canvas, true);
        var scene = new BABYLON.Scene(engine);

        // This creates and positions a free camera (non-mesh)
        var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);

        // This targets the camera to scene origin
        camera.setTarget(BABYLON.Vector3.Zero());

        // This attaches the camera to the canvas
        camera.attachControl(canvas, true);
        var light1: BABYLON.HemisphericLight = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
        var sphere = BABYLON.CreateSphere("sphere", { diameter: 1 }, scene);


        // Create a grid material
        var material = new MAT.GridMaterial("grid", scene);

        // Our built-in 'sphere' shape.
        var sphere = BABYLON.MeshBuilder.CreateSphere("sphere1", { segments: 16, diameter: 2 }, scene);

        // Move the sphere upward 1/2 its height
        sphere.position.y = 2;

        // Affect a material
        sphere.material = material;

        // Our built-in 'ground' shape.
        var ground = BABYLON.MeshBuilder.CreateGround("ground1", { width: 6, height: 6, subdivisions: 2 }, scene);

        // Affect a material
        ground.material = material;

        // hide/show the Inspector
        window.addEventListener("keydown", (ev) => {
            // Shift+Ctrl+Alt+I
            if (ev.shiftKey && ev.ctrlKey && ev.altKey && ev.key === 'i') {
                if (scene.debugLayer.isVisible()) {
                    scene.debugLayer.hide();
                } else {
                    scene.debugLayer.show();
                }
            }
        });

        // run the main render loop
        engine.runRenderLoop(() => {
            scene.render();
        });
    }
}
new App();

Any ideas? Thanks

Hi Owen, thanks for reporting! I’m currently away but will do my best to find the reason on mobile. Must be one of the last commits
Two very quick temporary solutions are to use 6.35, or add skipLibCheck to your tsconfig. Until it’s resolved

Update - a new version was released with a fix. The things you can do with your mobile nowadays! Everything, apart from ducking autocomplete

1 Like

amazing! Thanks @RaananW !