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

[BUG]: types don't resolve for @octokit/core on esm.sh #2762

Closed
1 task done
ThisGuyCodes opened this issue Nov 19, 2024 · 17 comments
Closed
1 task done

[BUG]: types don't resolve for @octokit/core on esm.sh #2762

ThisGuyCodes opened this issue Nov 19, 2024 · 17 comments
Labels
deno Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@ThisGuyCodes
Copy link

What happened?

deno check ... consistently errors when using octokit via esm.sh

Versions

Octokit.js v4.0.2
Deno v2.0.6

Relevant log output

$ deno check *.ts **/*.ts --allow-import
error: Failed resolving types. Relative import path "@octokit/core/types" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/[email protected]/X-ZS8q/dist-types/octokit.d.ts"
    at https://esm.sh/v135/[email protected]/X-ZS8q/dist-types/octokit.d.ts:4:59
$

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ThisGuyCodes ThisGuyCodes added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 19, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
Copy link
Member

This seems like an issue with esm.sh not resolving the import map

That import path is defined in package.json
https://unpkg.com/browse/@octokit/[email protected]/package.json (Line 67)

@wolfy1339 wolfy1339 added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Bug Something isn't working as documented Status: Triage This is being looked at and prioritized labels Nov 19, 2024
@ThisGuyCodes
Copy link
Author

I honestly don't know if I'm doing something wrong, I also opened an issue with esm.sh about a bug with their deno cli integration, and they told me they're deprecating it, so maybe it's got something to do with the way that added it to my import map?

here's what my import map looks like:

  "imports": {
    "deno-slack-api/": "https://deno.land/x/[email protected]/",
    "deno-slack-sdk/": "https://deno.land/x/[email protected]/",
    "mock-fetch/": "https://deno.land/x/[email protected]/",
    "@octokit/webhooks-types": "https://esm.sh/v135/@octokit/[email protected]",
    "octokit": "https://esm.sh/v135/*[email protected]",
    "@std/testing": "jsr:@std/testing@^1.0.5"
  },
  "scopes": {
    "https://esm.sh/v135/": {
      "@octokit/app": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/core": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/oauth-app": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/plugin-paginate-graphql": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/plugin-paginate-rest": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/plugin-rest-endpoint-methods": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/plugin-retry": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/plugin-throttling": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/request-error": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/types": "https://esm.sh/v135/@octokit/[email protected]"
    }
  }

@wolfy1339 wolfy1339 changed the title [BUG]: types don't resolve in Deno [BUG]: types don't resolve for @octokit/core on esm.sh Nov 19, 2024
@ThisGuyCodes
Copy link
Author

@wolfy1339 I notice you linked the @octokit/core package.json, but the error is saying it's not defined in the octokit package, is octokit somehow supposed to inherit the import map from @octokit/core?

(I genuinely have no idea how these things work)

@wolfy1339
Copy link
Member

wolfy1339 commented Nov 19, 2024

The octokit module is built on multiple other Octokit libraries packaged together, like @octokit/core, @octokit/app, @octokit/webhooks.

Sorry, I meant export map
https://nodejs.org/api/packages.html#exports

It defines the exports of that package, in that case, there's 2 exports.
./ is the main entrypoint
./types is a special entrypoint to access some types not exported in the main entrypoint but needed elsewhere.

The problem lies with esm.sh not using the export map in order to map the import to the correct file.

In the mean time, try adding the following to your scopes

"@octokit/core/types": "https://esm.sh/v135/@octokit/[email protected]/dist-types/types.d.ts",

Also, to prevent any type errors ditch the @octokit/webhooks-types package in favour of the @octokit/openapi-webhooks-types package. The former are not compatible with v4 of Octokit

@wolfy1339
Copy link
Member

Closing as there is nothing else actionable for Octokit itself

@wolfy1339 wolfy1339 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@github-project-automation github-project-automation bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Nov 19, 2024
@ThisGuyCodes
Copy link
Author

@wolfy1339 thanks for the workaround. Though it seems this just moved on to something else :(

$ deno check test.ts
error: Failed resolving types. Relative import path "node" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/@octokit/[email protected]/dist-types/RequestRequestOptions.d.ts"
    at https://esm.sh/v135/@octokit/[email protected]/dist-types/RequestRequestOptions.d.ts:1:22

it genuinely seems like I'm the only one doing this...

@wolfy1339
Copy link
Member

wolfy1339 commented Nov 19, 2024

please try to force it to use version 13.6.1 of @octokit/types

@ThisGuyCodes
Copy link
Author

ThisGuyCodes commented Nov 19, 2024

my scopes already has this:

"@octokit/types": "https://esm.sh/v135/@octokit/[email protected]"

I seriously don't know how to do what you're asking

@wolfy1339
Copy link
Member

Nevermind that. It's esm.sh keeping an old version of @octokit/types around

As for that error you are getting, it's TypeScript trying to shoehorn NodeJS typings into the project.
The issue seems to stem from AbortSignal which is not a Node specific API

The line in question is the following (https://unpkg.com/browse/@octokit/[email protected]/dist-types/RequestRequestOptions.d.ts)

/// <reference types="node" resolution-mode="require"/>

@wolfy1339
Copy link
Member

Will be fixed by octokit/types.ts#656

@ThisGuyCodes
Copy link
Author

Also, to prevent any type errors ditch the @octokit/webhooks-types package in favour of the @octokit/openapi-webhooks-types package. The former are not compatible with v4 of Octokit

@wolfy1339 Can you elaborate a bit more? I use this package like this:

import { WebhookEvent } from "@octokit/webhooks-types";

const handleWebhook = (payload) => {
  const event = payload as WebhookEvent;

  // type narrowing via stuff like this:
  if ("state" in event) {
    // TypeScript now considers event to be of type `StatusEvent`
  }
}

I can't figure out how to solve for my needs with @octokit/openapi-webhooks-types

@wolfy1339
Copy link
Member

See https://github.com/octokit/webhooks.js/releases/tag/v13.0.0

The types were completely redone and are not compatible.

import type { webhooks as OpenAPIWebhooks } from "@octokit/openapi-webhooks-types";
export type WebhookEventDefinition<TEventName extends keyof OpenAPIWebhooks> =
  OpenAPIWebhooks[TEventName]["post"]["requestBody"]["content"]["application/json"];
export type StatusEvent = WebhookEventDefinition<"status">;

I am working on making a transition package that drops in and replaces @octokit/webhooks-types and will resolve everything into friendlier types

@wolfy1339
Copy link
Member

Try using @octokit/openapi-webhooks-types-transition

@ThisGuyCodes
Copy link
Author

@wolfy1339 works perfect with no other code changes! ❤️

renovate bot added a commit to WtfJoke/setup-tectonic that referenced this issue Dec 2, 2024
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@octokit/types](https://redirect.github.com/octokit/types.ts) |
[`13.6.1` ->
`13.6.2`](https://renovatebot.com/diffs/npm/@octokit%2ftypes/13.6.1/13.6.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@octokit%2ftypes/13.6.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@octokit%2ftypes/13.6.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@octokit%2ftypes/13.6.1/13.6.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@octokit%2ftypes/13.6.1/13.6.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>octokit/types.ts (@&#8203;octokit/types)</summary>

###
[`v13.6.2`](https://redirect.github.com/octokit/types.ts/releases/tag/v13.6.2)

[Compare
Source](https://redirect.github.com/octokit/types.ts/compare/v13.6.1...v13.6.2)

##### Bug Fixes

- remove `@types/node` from generated types
([#&#8203;656](https://redirect.github.com/octokit/types.ts/issues/656))
([730a26d](https://redirect.github.com/octokit/types.ts/commit/730a26dc2d919f19ed5401ffdf83286181da8772)),
closes
[/github.com/octokit/octokit.js/issues/2762#issuecomment-2486997620](https://redirect.github.com//github.com/octokit/octokit.js/issues/2762/issues/issuecomment-2486997620)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone
Europe/Berlin, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/WtfJoke/setup-tectonic).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xOS4wIiwidXBkYXRlZEluVmVyIjoiMzkuMTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
@wolfy1339
Copy link
Member

@ThisGuyCodes
I managed to get deno check to work using the following import map

"scopes": {
    "https://esm.sh/v135/": {
      "@octokit/app": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/core": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/core/types": "https://esm.sh/v135/@octokit/[email protected]/dist-types/types.d.ts",
      "@octokit/oauth-app": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-paginate-graphql": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-paginate-rest": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-rest-endpoint-methods": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-retry": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-throttling": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/request-error": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/types": "https://esm.sh/v135/@octokit/[email protected]",
      "@octokit/request": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/graphql": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "before-after-hook": "https://esm.sh/v135/[email protected]"
    }
  }

I had to add the dependency override for esm.sh, as documented here: https://esm.sh/#specifying-dependencies

The esm.sh deno thingy missed adding @octokit/graphql, before-after-hook and @octokit/request

wolfy1339 added a commit to octokit/oauth-app.js that referenced this issue Dec 28, 2024
For some reason, TypeScript is including references to `@types/node` in the generated types.

See octokit/types.ts#656
See octokit/octokit.js#2762 (comment)
wolfy1339 added a commit to octokit/oauth-app.js that referenced this issue Dec 29, 2024
For some reason, TypeScript is including references to `@types/node` in the generated types.

See octokit/types.ts#656
See octokit/octokit.js#2762 (comment)
@wolfy1339
Copy link
Member

wolfy1339 commented Jan 8, 2025

We still have this issue to contend with, esm-dev/esm.sh#995.

I got rid of all @types/node on the Octokit side of things

I got deno check to work:

{
  "imports": {
    "octokit": "https://esm.sh/v135/*[email protected]?target=deno",
    "_http_agent": "node:_http_agent",
    "_http_client": "node:_http_client",
    "_http_common": "node:_http_common",
    "_http_incoming": "node:_http_incoming",
    "_http_outgoing": "node:_http_outgoing",
    "_http_server": "node:_http_server",
    "_stream_duplex": "node:_stream_duplex",
    "_stream_passthrough": "node:_stream_passthrough",
    "_stream_readable": "node:_stream_readable",
    "_stream_transform": "node:_stream_transform",
    "_stream_wrap": "node:_stream_wrap",
    "_stream_writable": "node:_stream_writable",
    "_tls_common": "node:_tls_common",
    "_tls_wrap": "node:_tls_wrap",
    "assert": "node:assert",
    "assert/strict": "node:assert/strict",
    "async_hooks": "node:async_hooks",
    "buffer": "node:buffer",
    "child_process": "node:child_process",
    "cluster": "node:cluster",
    "console": "node:console",
    "constants": "node:constants",
    "crypto": "node:crypto",
    "dgram": "node:dgram",
    "diagnostics_channel": "node:diagnostics_channel",
    "dns": "node:dns",
    "dns/promises": "node:dns/promises",
    "domain": "node:domain",
    "events": "node:events",
    "fs": "node:fs",
    "fs/promises": "node:fs/promises",
    "http": "node:http",
    "http2": "node:http2",
    "https": "node:https",
    "inspector": "node:inspector",
    "inspector/promises": "node:inspector/promises",
    "module": "node:module",
    "net": "node:net",
    "os": "node:os",
    "path": "node:path",
    "path/posix": "node:path/posix",
    "path/win32": "node:path/win32",
    "perf_hooks": "node:perf_hooks",
    "process": "node:process",
    "punycode": "node:punycode",
    "querystring": "node:querystring",
    "readline": "node:readline",
    "readline/promises": "node:readline/promises",
    "repl": "node:repl",
    "stream": "node:stream",
    "stream/consumers": "node:stream/consumers",
    "stream/promises": "node:stream/promises",
    "stream/web": "node:stream/web",
    "string_decoder": "node:string_decoder",
    "sys": "node:sys",
    "timers": "node:timers",
    "timers/promises": "node:timers/promises",
    "tls": "node:tls",
    "trace_events": "node:trace_events",
    "tty": "node:tty",
    "url": "node:url",
    "util": "node:util",
    "util/types": "node:util/types",
    "v8": "node:v8",
    "vm": "node:vm",
    "wasi": "node:wasi",
    "worker_threads": "node:worker_threads",
    "zlib": "node:zlib"
  },
  "scopes": {
    "https://esm.sh/v135/": {
      "@octokit/app": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/auth-app": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/auth-unauthenticated": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/core": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/core/types": "https://esm.sh/v135/@octokit/[email protected]/dist-types/types.d.ts?target=deno",
      "@octokit/oauth-app": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/plugin-paginate-graphql": "https://esm.sh/v135/@octokit/[email protected]?deps=@octokit/[email protected]",
      "@octokit/plugin-paginate-rest": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/plugin-rest-endpoint-methods": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/plugin-retry": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/plugin-throttling": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/request-error": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/types": "https://esm.sh/v135/@octokit/[email protected]?target=deno",
      "@octokit/webhooks": "https://esm.sh/v135/@octokit/[email protected]?target=deno"
    }
  }
}

@wolfy1339 wolfy1339 added the deno label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

2 participants