BabylonJS Typescript imports fail for MochaJS specs

Has anybody had any new insights on this topic? If I can contribute something on top of the provided demo case, please let me know!

It looks like you are using a special loader ts-node/esm and I am wondering if you do not need another one to consume es6 import styles from our package in mocha. Did you check with them on Github or their forum ???

@sebavan thanks for the suggestion. I actually tried a couple of things, but it’s just shifting the problem around (read: solving one, opening another) as you can see in the several branches. I tried with Jasmine as well and ran into the same problem: With BabylonJS we are looking at an ES5 implementation that uses ES6 imports. Mocha, Jasmine and other teams will push us back (up the chain) as the unit of test evolves around BabylonJS.

In this case babel could transpile import style to es5 with the import transform plugin. This is actually what jest users are using.

I guess you are talking about this thread here?

The babel-plugin-transform-imports will probably not solve the issue here.

1 Like

To provide some more info: The demo-repo has been updated with a somehow “working” state. After several tries and lots of errors, I went with instant-mocha, which is a bundle that packages all the magic of Babel, Webpack, etc. The tsconfig.json and so on are provided. But I just worked around the issue.

When you install everything in the demo and run are-you-es5 check -r ., you’ll see the actual error - exactly as you described - with the imports. I am still searching for a real solution as I could not get the transpilation sorted in an order that just works and tackles the es6 imports. If you could provide some lines, I’d be grateful. Thanks in advance!

(And thanks for restoring the post!)

But this is exactly what the babel plugin should sort out transforming es6 import style to es5.

Adding @RaananW who might have other options ?

1 Like

i’ll download the code tomorrow and see if I can understand the issue better

1 Like

Hi there!

I’m facing the same problems as @fjk.

We’re working on a TS project using Webpack & BabylonJS and are a little stuck on making our code testable as importing certain classes from BabylonJS always breaks the tests with different errors.

We’re not “bound” to a specific testing framework ATM but we were not able to succeed with any we’ve tried so far (mocha, jest, jasmine).

Our experience is very similar to what @fjk describes. Especially “shifting the problem around (read: solving one, opening another)” pretty much brings it to the point.

In the end all issues we’ve seen so far have something to do with importing BJS classes into our tests.

I’d really appreciate some progress or help on this as well!


I’ll set this issue to be a high priority, add it seems to be affecting different projects. As I was away till today it would be great to hear from you if it was resolved by you in any way.


@RaananW sure I will! Just ping me and tell me where I can contribute my time. Thanks in advance!

1 Like

hey! finally found the time to look into the code. After finalizing the install (i am running on windows so no sh commands for me :-)) I managed to run the tests:

both passed on first run.

Note - I am running node 12 and not 14, but I don’t believe this is the case here.
I also had to install mocha in the project itself, as I don’t have it installed globally (which is probably the case on your system?

The repository has two npm run commands, but they are both undefined. there was only one test script, and it seems to be working.
Would be great to get it to fail though, so I will know what you are experiencing :slight_smile:

I had the same problem - I made a separate tsconfig for testing with target commonjs.
react-babylonjs/tsconfig.test.json at master · brianzinn/react-babylonjs (

In my script I also have “require esm”:
cross-env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha --require ts-node/register --require esm \"test/**/*.spec.{js,jsx,ts,tsx}\"

here is a vscode launch config for debugging tests with breakpoints as well:

          "type": "node",
          "request": "launch",
          "args": [
          "internalConsoleOptions": "openOnSessionStart",
          "name": "Mocha Tests",
          "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
          "skipFiles": [
          "env": {
            "TS_NODE_PROJECT": "tsconfig.test.json",
            "TS_NODE_TRANSPILE_ONLY": "true",
          "runtimeArgs": [

I have exact same problem with TypeScript and Jest :thinking:

Note that I’m using Node.js v14.17.6 (and npm v6.14.15)

is there a project you can share so i can see it fails and be able to track the reason?

Also this should help Jest is crashing - #4 by sebavan the import should be converted on the js side

i made it work with mochapack, which is really great to work with btw. It will rerun tests only relevant to the changed source files. It actually makes me sad/angry that webpack breaks things so often, its kind of hard to rely on anything built on webpack.