Double slash in cannonJSPlugin.js may lead to 404 Not Found

In @babylon/core version 6.13.0 (installed with npm), there is one file that contains an import with a double forward slash that is preventing Babylon.js from running with some servers.

The file in question is:
@babylonjs/core/Physics/v1/Plugins/cannonJSPlugin.js

Line 4:
import { PhysicsImpostor } from "..//physicsImpostor.js";

Some servers will interpret “//” as “/../” (parent directory), which I believe is unintended. If I erase one of the slashes, my server can load Babylon.js without problems. If I keep the double slash, my server cannot find the scripts. See image below:

I tested three different servers:

  • VSCode’s Live Server - Does not work (see image)
  • simple-http-server - Does not work (see image)
  • A simple Node.js server I implemented myself - Works perfectly

I’m using Windows 11.

How to reproduce:

  1. In an empty directory: npm init
  2. Install @babylonjs/core with npm: npm install @babylonjs/core
  3. Create a file index.html with the following content exactly: <script type="module">import * as BABYLON from "./node_modules/@babylonjs/core/index.js";</script>
  4. Use VSCode with the Live Server extension, start a live server, and open the URL in any browser

Now you can open the browser’s console and see the errors like in the image above.

Then open the file ./node_modules/@babylonjs/core/Physics/v1/Plugins/cannonJSPlugin.js and remove one of the two slashes in line 4 (it should then look like this: import { PhysicsImpostor } from "../physicsImpostor.js";). Now refresh the web page and there will be no errors.

1 Like

let’s see what happened there :slight_smile:

Thanks for reporting.

fix imports by RaananW · Pull Request #14078 · BabylonJS/Babylon.js (github.com)

1 Like