Viewer seems broken on ES6

There’s apparently something wrong with @babylonsjs/viewer, alpha58. This is easy to reproduce with GitHub - shamsail/babylonjsviewer (with package.json altered to get babylon’s latest alpha version):

yarn run serve


These dependencies were not found:

* @babylonjs/core.js in ./node_modules/@babylonjs/viewer/index.js
* @babylonjs/loaders.js in ./node_modules/@babylonjs/viewer/index.js

To install them, you can run: npm install --save @babylonjs/core.js @babylonjs/loaders.js

Taking a look at node_modules/@babylonjs/viewer/index.js these are the offending lines:

import * as BABYLON from '@babylonjs/core.js';
// load needed modules.
import '@babylonjs/loaders.js';

But even manually removing .js other errors show up. Apparently .js is being automatically appended to imports where it shouldn’t be.

The .js extensions are needed on imports that are files - if you don’t do so then webpack 5 ends up complaining if you don’t specify extensions when the NPM is a module (ie: type: ‘module’ in package.json). Looks like an issue in build script though… likely @RaananW knows what’s going on there.

Adding @RaananW to the party :slight_smile:

Ah, I see. But the issue is that .js is being added to imports from directories, not only files. So it should be either @babylonjs/loaders or @babylonjs/loaders/index.js.


And I guess some of the latest build changes to add the .js suffix in ES6 have broken it:

Yes! That’s very interesting. I’ll fix it for the next npm release.
Thanks for reporting!

1 Like

Fix submitted, next viewer release will be fixed. Thanks again!

1 Like

Hi there,

I am having trouble building with vite and rollup (sveltekit) and the mentioned lines seem to be the problem. Using “@babylonjs/viewer”: “^5.5.0”

The build fails with this:

[vite]: Rollup failed to resolve import "@babylonjs/loaders/.js" from "node_modules/@babylonjs/viewer/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to

This is what the line looks like in @babylonjs/viewer/index.js

Screenshot from 2022-05-05 11-56-21

And it works if I change it to:
Screenshot from 2022-05-05 11-57-26

I will fix that asap. thanks for notifying!

1 Like

please try latest npm package, it should be fine now.