Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The jsDelivr ESM link doesn't work for Box2D-WASM #18510

Open
3 tasks done
8Observer8 opened this issue Jul 8, 2023 · 2 comments
Open
3 tasks done

The jsDelivr ESM link doesn't work for Box2D-WASM #18510

8Observer8 opened this issue Jul 8, 2023 · 2 comments
Assignees

Comments

@8Observer8
Copy link

8Observer8 commented Jul 8, 2023

Description

The main contributor for Plunker wrote in the next message that it can be an issue of jsDelivr or Box2D-WASM: plnkr/feedback#597 (comment) So I created the issue for Box2D-WASM too: Birch-san/box2d-wasm#61

I try to use the box2d-wasm@7.0.0 ESM link from here: https://www.jsdelivr.com/package/npm/box2d-wasm

It doesn't work on Plunker, and it doesn't work locally on my laptop (I have the same errors, see errors below):

But it works on PlayCode: https://playcode.io/1527756

I uploaded Box2D-WASM files on GitHub Pages:

image

So it works locally and on Plunker if I use the next link: https://8observer8.github.io/lib/box2d-wasm-7.0.0-box2d-2.4.1/box2d-wasm.min.js You can just replace the jsDelivr link with this one.

index.html

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>

<body>
    <!-- Since import maps are not yet supported by all browsers, its is
        necessary to add the polyfill es-module-shims.js -->
    <script async src="https://unpkg.com/es-module-shims@1.7.3/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "box2d-wasm": "https://cdn.jsdelivr.net/npm/box2d-wasm@7.0.0/+esm",
                "gl-matrix": "https://cdn.jsdelivr.net/npm/gl-matrix@3.4.3/+esm"
            }
        }
    </script>

    <script type="module" src="./js/index.js"></script>
</body>

</html>

index.js

import { box2d, initBox2D } from "./init-box2d.js";

async function init() {
    await initBox2D();

    const {
        b2Vec2
    } = box2d;

    const vec = new b2Vec2(1, 2);
    console.log(`vec = (x: ${vec.x}, y: ${vec.y})`);
}

init();

init-box2d.js

import Box2DLib from "box2d-wasm";

export let box2d = null;

export function initBox2D() {
    return new Promise(resolve => {
        Box2DLib().then((re) => {
            box2d = re;
            resolve();
        });
    });
}

But I have these errors:

image

Affected jsDelivr links

https://cdn.jsdelivr.net/npm/box2d-wasm@7.0.0/+esm

Response headers

None

Information

  • Device OS: Window 10
  • Browser & Version: Chrome Version 114.0.5735.199 (Official Build) (64-bit)
  • VPN provider (if you use one)
  • Russia, Saratov

Requisites

  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue.
  • I checked the documentation to understand that the issue I am reporting is not normal behavior.
  • I understand that not filling out this template correctly will lead to the issue being closed.

Additional content

No response

@8Observer8 8Observer8 changed the title The jsDelivr ESM link doesn't work for Box2d-WASM The jsDelivr ESM link doesn't work for Box2D-WASM Jul 8, 2023
@MartinKolarik
Copy link
Member

This looks like an ESM version of #18488 where the /+esm suffix breaks resolving of relative paths constructed based on import.meta.url. We rewrite paths for import() calls but dynamically constructed fetch() won't work for with relative paths with our current implementation.

@8Observer8
Copy link
Author

8Observer8 commented Mar 5, 2024

UNPKG version works without the problem:

Playground: https://plnkr.co/edit/BGNYcIJRiJXpd9N4?preview

    <!-- Since import maps are not yet supported by all browsers, its is
        necessary to add the polyfill es-module-shims.js -->
    <script async src="https://cdn.jsdelivr.net/npm/es-module-shims@1.8.3/dist/es-module-shims.min.js"></script>

    <script type="importmap">
        {
            "imports": {
                "box2d-wasm": "https://unpkg.com/box2d-wasm@7.0.0/dist/es/Box2D.js",
                "gl-matrix": "https://cdn.jsdelivr.net/npm/gl-matrix@3.4.3/+esm"
            }
        }
    </script>

    <script type="module">
        import { mat4, vec3 } from "gl-matrix";

        const v = vec3.fromValues(1, 2, 3);
        console.log(v);

        const m = mat4.create();
        console.log(m);
    </script>

    <!-- <script type="module" src="./js/index.js"></script> -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants