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.

Exactly

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