physx-js icon indicating copy to clipboard operation
physx-js copied to clipboard

physx-js as ES6 module

Open 8Observer8 opened this issue 3 years ago • 0 comments

Hello,

I am trying to use physx-js v0.7.0 as ES6 module but I have this error:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec.

Sandbox: https://plnkr.co/edit/B0kWbwZqFipXnFIX?preview

<body>
    <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "physx-js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/physx.release.js",
                "physx-js-wasm": "https://cdn.jsdelivr.net/npm/[email protected]/dist/physx.release.wasm"
            }
        }
    </script>

    <script type="module">
        import physx from "physx-js";
        import physxModule from "physx-js-wasm";

        const PhysX = physx({
            locateFile(path)
            {
                if (path.endsWith(".wasm"))
                {
                    return physxModule;
                }
                return path;
            },
            onRuntimeInitialized()
            {
                console.log("PhysX loaded");
            }
        });
    </script>
</body>

8Observer8 avatar Jul 05 '22 20:07 8Observer8