Skip to content

Resolving repository root does not correctly work for forks of packages #1247

@hybridherbst

Description

@hybridherbst

I'm running into an issue where our fork of three.js does not properly work when served from esm.sh.
I pinpointed that one of the root causes is incorrect module resolution.

Looking at this module file:

https://esm.sh/[email protected]/es2022/examples/jsm/loaders/RGBELoader.mjs

the module correctly references the core three.mjs module from a relative path:

import {LinearSRGBColorSpace as Y}from"../../../three.mjs"

However, in our fork,

https://esm.sh/@needle-tools/[email protected]/es2022/examples/jsm/loaders/RGBELoader.mjs

the module incorrectly references three.js directly:

import {LinearSRGBColorSpace as Y}from"/three?target=es2022"

This results in the [email protected] version pulling in the completely wrong "latest" version of three.js as dependency, namely https://esm.sh/three?target=es2022 --> resolves to 0.181.2.

Is there a way to tell esm.sh that "three" in this case is an alias for "@needle-tools/three" so that it correctly resolves those references and turns them into relative references?

This is a regular fork of three.js without further modifications, the source of that module looks like this:

EDIT:
Forgot to mention that I already have this in the importmap, but it does not seem to be respected for this kind of path resolution ("/three" is still resolved to "https://esm.sh/three")

  <script type="importmap">
  {
    "imports": {
      "@needle-tools/engine": "https://esm.sh/@needle-tools/engine?standalone",
      "three": "https://esm.sh/@needle-tools/[email protected]"
    }
  }
  </script>

The full chain looks like this:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions