Build error: "Missing Dependency: module"

I’m running into an odd issue on attempting to build my project (.zip export). My project runs just fine when using the launch page, but if I attempt to build the project, I get the error below:

Is there any way to track down specifically where the missing dependency is popping up?

I will add that I’m using a modified (to work in editor projects) version of the Jolt Physics implementation that @LeXXik is a part of:

Since it’s currently in testing, I have been using the debug version, but I will try the production version here in a little while and see if that clears things up. Otherwise, is there any way to potentially track down the missing dependency?

My settings include:

  • Concatenate Scripts
  • Minify Scripts
  • Optimize Screen Format

Any help or ideas would be very appreciated!

Edit: Can confirm the issue exists with the production build of the physics implementation.

@yak32 @KPal

Could be the same issue I discussed with @KPal. @eproasim try disabling the script concatenation/minification. If it works, then it is the problem with the dynamic imports, that clones the scripts. which is a known issue.

Thank you for the suggestion @LeXXik ! I just tried disabling minification and concatenation still have the same error occurring. I’ll keep poking around, and see if I can get something to work.

I found the issue! Or, should I say, Gemini + Roo found the issue. The jolt-physics glue code includes a check for a web environment and does some node specific imports if a web environment is not detected. I deleted the import of the module library in the glue code (line 11 in my case) and the build resolved with no issues.

Hmm, not sure this is a solution. I mean, the Editor should be able to generate a build for you, regardless of how Emscripten generated the glue code. So, something for @KPal and @yak32 too look at still.

By jolt-physics glue code, you mean the Jolt’s library glue code, right? Do you have the same issue, if you’d try to download Ammo glue code? Ammo might be a bit old, though, so try using the one from the repo instead:

Edit: I will mark the topic as unsolved for now.

This is correct!

So I tested with the the linked version of Ammo and had no issue with creating my build. I investigated the glue code to see if it had any similar import commands to the dist of the joly-physics library, and it did not.

The specific line of code that can be found on line 11 jolt-physics.wasm.js (from ‘dist’) is:

```if(fa){const {createRequire:a}=await import(“module”);var require=a(import.meta.url)}```

Removing this line results in a successful build, but there are a couple of interesting caveats.

  1. Scripts cannot be concatenated (Sounds like this is a known issue)
  2. It seems like the paths to the resources are broken.

When I attempt to visit the built project, the Jolt initialization fails because it cannot find the glue code. Closer inspection reveals that the project is looking for the files at:

[PROJECT]/js/esm-scripts/Scripts/lib/js/esm-scripts/Scripts/lib/jolt-physics.wasm.mjs

While the files are actually at:

[PROJECT]/js/esm-scripts/Scripts/lib/jolt-physics.wasm.mjs

If I add the extra folder layers in my S3 bucket, the project works with no issues. It’s weird because I use ```assets.find().getFileUrl()``` to find the required assets:

import { Script } from 'playcanvas';
import { init } from './lib/physics.min.mjs';

export class PhysicsInit extends Script {

    static scriptName = 'joltPhysics';

    async initialize() {
        try {
            console.log("Initializing Jolt Physics...");

            const wasmAsset = this.app.assets.find('jolt-physics.wasm.wasm').getFileUrl();
            const glueAsset = this.app.assets.find('jolt-physics.wasm.mjs').getFileUrl();
            const dispatcherAsset = this.app.assets.find('dispatcher.min.mjs').getFileUrl();
            await init(this.app, {
                fixedStep: 1 / 60,
                // useSharedArrayBuffer: true,
                // useWebWorker: true,
                useMotionState: true,
                wasmUrl: wasmAsset,
                glueUrl: glueAsset,
                dispatcherUrl: dispatcherAsset,
                contactEventsEnabled: true,
            });

            this.app.fire('physics:ready');
            console.log("Jolt Physics Initialized!");
        } catch (err) {
            console.error("Failed to init physics:", err);
        }
    }
}

I’m going to try setting them as Asset attributes and see if that fixes the pathing issues.

Edit: Actually scratch that. I thought through it. Setting the assets to attributes would result in the same problem since the physics init function requires URL’s as the asset parameters.

Edit: I think I fixed the file finding my reconstructing my asset URL’s the same way the physic’s library does, at least for Playcanvas hosted builds, but I’m assuming it should work for self hosted builds. Will report back, if not.

Hmm, I also noticed you are looking for jolt-physics.wasm.mjs glue file, with .mjs extension. I think by default Emscripten generates it with .js. Are you changing it manually? I think you want to keep it as .js.

That’s correct. I had to rename the file in the editor, otherwise the launch page would issue a

Uncaught SyntaxError: import.meta may only appear in a module

error.

I see. You can fix it by disabling the preload on both Wasm and the glue files. The physics library you are using will handle the loading. This way the launcher will not try to parse the glue script.

1 Like