Cannot find some babylonjs module when starting new typescript project

Hi, I’m new to babylonjs and want to start a new project that uses babylonjs with typescript (and electron). However, I consistently encounter typescript build errors. I create an empty folder with the following package.json:

{
  "name": "yourapp",
  "version": "0.0.1",
  "description": "Your Application",
  "main": "./app/main.js",
  "scripts": {
    "build": "tsc",
    "start": "electron ./app/main.js",
    "dist": "build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "dependencies": {
    "babylonjs": "6.28.1"
  },
  "devDependencies": {
    "electron": "25.9.4",
    "electron-builder": "24.6.4",
    "typescript": "5.2.2"
  },
  "build": {
    "appId": "yourappid",
    "dmg": {
      "contents": [
        {
          "x": 110,
          "y": 0
        },
        {
          "x": 240,
          "y": 0,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "win": {
      "target": "portable"
    }
  }
}

Then after I run npm install successfully, I run npm run build, result was:

> yourapp@0.0.1 build
> tsc

node_modules/babylonjs/babylon.module.d.ts:28800:28 - error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.

28800 import { Animatable } from "babylonjs/Animations";
                                 ~~~~~~~~~~~~~~~~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:28819:52 - error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.

28819 import { Animatable, Animation, IAnimatable } from "babylonjs/Animations";
                                                         ~~~~~~~~~~~~~~~~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:28882:28 - error TS2307: Cannot find module 'babylonjs/Animations' or its corresponding type declarations.

28882 import { Animatable } from "babylonjs/Animations";
                                 ~~~~~~~~~~~~~~~~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:71427:46 - error TS2307: Cannot find module 'babylonjs/Meshes' or its corresponding type declarations.

71427     protected _createVertexBuffers(): import("babylonjs/Meshes").VertexData;
                                                   ~~~~~~~~~~~~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:71537:46 - error TS2307: Cannot find module 'babylonjs/Meshes' or its corresponding type declarations.

71537     protected _createVertexBuffers(): import("babylonjs/Meshes").VertexData;
                                                   ~~~~~~~~~~~~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:176187:18 - error TS2300: Duplicate identifier 'Plane'.

176187     export class Plane {
                        ~~~~~

node_modules/babylonjs/babylon.module.d.ts:184603:11 - error TS2300: Duplicate identifier 'Plane'.

184603     class Plane {
                 ~~~~~

node_modules/babylonjs/babylon.module.d.ts:184655:11 - error TS2300: Duplicate identifier 'Polygon'.

184655     class Polygon {
                 ~~~~~~~

node_modules/babylonjs/babylon.module.d.ts:192657:18 - error TS2300: Duplicate identifier 'Polygon'.

192657     export class Polygon {
                        ~~~~~~~


Found 9 errors in the same file, starting at: node_modules/babylonjs/babylon.module.d.ts:28800

My environment is:

Machine: Macbook Pro with M1 Chip
OS: macOS 13.2.1
node version: 19.7.0 (installed from brew)
npm version: 9.5.0

I have to post stuff like this because the problem cannot be reproduced in the playground. Sorry for the inconvenience, and thanks in advance.

I believe @RaananW fixed a build error with duplicate names that involved the Polygon class, is that correct?

Try using es6 packages instead

npm i @babylonjs/core

It has been fixed in version 6.29 but I would advice to wait for 6.29.1 as there is an input issue at the moment and we ll republish in no time.

1 Like

Thanks, it works like a charm!

1 Like