Trouble with @babylonjs es6 modules and jest and typescript

@RaananW so I have no jest configuration and any presets would be those that create-react-app came with I believe. I recreated a repo of the bug that breaks on my machine but it seems to work just fine on codesandbox and I have no idea why. I have set the node version to 16.

Hey @ecoin you seem far more familiar with what could be going on under the hood than I am. I tried using the jest.config.js + config.js which didn’t work. To help me debug, would you mind explaining at a high level what you think the issue is? For example (and I’m using terms that I don’t quite understand so bear with me), are you saying that the library @bablyonjs/core gets compiled to ES6 Javascript and that the Jest associated with create-react-app only understands ES5 Javascript so Jest is complaining that there is invalid syntax because its ES6 instead of ES5?

Basically, if I can better understand what you think the issue is, I think that could help me a lot to debug!

UPDATE: @ecoin you were right! The issue was that since I was using create-react-app, jest wasn’t respecting the jest.config.js file. However, once I added

"jest": {
    "transformIgnorePatterns": ["/node_modules/(?!@babylonjs)(.*)"]
  }

to my package.json file the test ran!

1 Like

Yes, you are correct, I had this same issue before, only with Next.js. But CRA is the same (I use them both on daily job).

Most well written boilerplate solutions, like CRA, automatically skip compilation of external npm packages when you add them via npm install or yarn add.

When using @babylon, you need to make an exception to this default rule, by explicitly telling CRA to compile the @babylon package, even if it’s inside node_modules.

Now, I don’t know what your CRA config look like, so I cannot help.

Alternatively, if you are starting a project from scratch, I would recommend as ready boilerplate like this. I created it recently from an existing production site, so can answer any questions if you use that setup.

2 Likes