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

Import map doesn't resolve transitive dependency #480

Closed
cyco130 opened this issue Dec 29, 2022 · 3 comments
Closed

Import map doesn't resolve transitive dependency #480

cyco130 opened this issue Dec 29, 2022 · 3 comments
Labels
deno Not working in Deno

Comments

@cyco130
Copy link

cyco130 commented Dec 29, 2022

I've initialized a Deno project with the esm.sh CLI and I added the @hattip/router module with deno task esm:add @hattip/router. The import map looks like this after that:

{
  "imports": {
    "@hattip/router": "https://esm.sh/v102/*@hattip/router@0.0.24"
  },
  "scopes": {
    "@hattip/router": {
      "@hattip/compose": "https://esm.sh/v102/@hattip/compose@0.0.24",
      "@hattip/core": "https://esm.sh/v102/@hattip/core@0.0.24"
    }
  }
}

But trying to import @hattip/router gives the following error:

error: Relative import path "@hattip/compose" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v102/@hattip/router@0.0.24/X-ZS8q/deno/router.js"
    at https://esm.sh/v102/@hattip/router@0.0.24/X-ZS8q/deno/router.js:2:25

I'm not well acquainted with esm.sh yet, am I supposed to esm:add transitive deps too (@hattip/compose in this case) or is this a bug?

The same happens with the browser and changing the scope from @hattip/router to https://esm.sh/v102/@hattip/router@0.0.24/ fixes it for both.

@cyco130 cyco130 added the deno Not working in Deno label Dec 29, 2022
@ije
Copy link
Member

ije commented Dec 30, 2022

seems the CLI script not create correct imports, i will look into it! Thanks.
you can change the import maps to below one that should work

{
  "imports": {
    "@hattip/router": "https://esm.sh/v102/*@hattip/router@0.0.24",
    "@hattip/compose": "https://esm.sh/v102/@hattip/compose@0.0.24",
    "@hattip/core": "https://esm.sh/v102/@hattip/core@0.0.24"
  }

@jollytoad
Copy link

I've just encounter this too.

The problem is that the scopes need to be listed as the resolved URLs.

For example, if I do: deno task esm:add rxjs, I get the following import map:

{
  "imports": {
    "rxjs": "https://esm.sh/v102/*rxjs@7.8.0",
    "rxjs/": "https://esm.sh/v102/*rxjs@7.8.0/"
  },
  "scopes": {
    "rxjs": {
      "tslib": "https://esm.sh/v102/tslib@2.4.1"
    },
    "rxjs/": {
      "tslib": "https://esm.sh/v102/tslib@2.4.1"
    }
  }
}

but Deno cannot resolve tslib because the scopes are wrong, I get an error like this when doing deno check **/*.ts...

error: Relative import path "tslib" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v102/rxjs@7.8.0/X-ZS8q/deno/internal/util/isReadableStreamLike.js"
    at https://esm.sh/v102/rxjs@7.8.0/X-ZS8q/deno/internal/util/isReadableStreamLike.js:2:47

The scope keys should be the resolved URLs like this...

{
  "imports": {
    "rxjs": "https://esm.sh/v102/*rxjs@7.8.0",
    "rxjs/": "https://esm.sh/v102/*rxjs@7.8.0/"
  },
  "scopes": {
    "https://esm.sh/v102/rxjs@7.8.0": {
      "tslib": "https://esm.sh/v102/tslib@2.4.1"
    },
    "https://esm.sh/v102/rxjs@7.8.0/": {
      "tslib": "https://esm.sh/v102/tslib@2.4.1"
    }
  }
}

which appears to work ok.

@jollytoad
Copy link

You could also have a single scope for esm.sh if you want to align on the same version of each dep:

  "scopes": {
    "https://esm.sh/": {
      "tslib": "https://esm.sh/v102/tslib@2.4.1"
    }
  }

@ije ije closed this as completed in 7c4cc77 Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno Not working in Deno
Projects
None yet
Development

No branches or pull requests

3 participants