Trying to use babylon.js with Typescript on NestJS server

import {Scene, NullEngine} from '@babylonjs/core';

simulateGame() {
    const engine = new NullEngine();
    const scene = new Scene(engine);
  }

I can’t make the NestJS server start anymore.

I keep on getting:

@babylonjs/core/index.js:1
export * from "./abstractScene";
^^^^^^

SyntaxError: Unexpected token export
    at Module._compile (internal/modules/cjs/loader.js:721:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)

My tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "exclude": ["node_modules", "dist"]
}

I’m pretty sure this is a node + ts issue but i can’t figure it out.
Does anyone have an idea what might be the issue?
I tried importing with require as well.

pinging @sebavan, the keeper of the Deep Dark Secrets of the Modules

i am totally not sure you can use “module”: “commonjs”, by relying on our es version of Babylon.

In your case it might be simpler to rely on the babylonjs package ?

1 Like