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]: app.getInstallationOctokit() throws error #455

Open
1 task done
Udbhav8 opened this issue Aug 25, 2023 · 5 comments
Open
1 task done

[BUG]: app.getInstallationOctokit() throws error #455

Udbhav8 opened this issue Aug 25, 2023 · 5 comments
Labels
Status: Needs info Full requirements are not yet known, so implementation should not be started Type: Bug Something isn't working as documented
Projects

Comments

@Udbhav8
Copy link

Udbhav8 commented Aug 25, 2023

What happened?

import fs from "node:fs"

import { App } from "@octokit/app"
import { type Octokit } from "@octokit/core"
import { Cache } from "@sift/util"

import { type GithubClientCredentials } from "./types"

const githubCache = new Cache<GithubClientCredentials, Promise<Octokit>>()

const createGithubClient = async (credentials: GithubClientCredentials) => {
  credentials.privateKey = fs.readFileSync("private-key.pem", "utf8")
  const app = new App({
    appId: credentials.appId,
    privateKey: credentials.privateKey,
  })

  const installationOctokit = await app.getInstallationOctokit(40990679)
  return installationOctokit
}

const getGithubClient = (githubClientCredentials: GithubClientCredentials) =>
  githubCache.getAndCache(githubClientCredentials, createGithubClient)

export default getGithubClient

The app.getInstallationOctokit() function does not behave as expected and throws the error message given below.
It looks like the error originates from the library universal-github-app-jwt library which is using the browser version of node instead.

Versions

octokit/app: ^14.0.0
node version : v18.17.0

Relevant log output

`[14:42:17.311] ERROR (68072): Error while handling interaction 
    err: {
      "type": "ReferenceError",
      "message": "crypto is not defined",
      "stack":
          ReferenceError: crypto is not defined
              at getToken (/Users/udbhavagarwal/Documents/GitHub/sift/node_modules/@octokit/auth-app/node_modules/universal-github-app-jwt/dist-src/get-token-browser.js:13:25)
              at githubAppJwt (/Users/udbhavagarwal/Documents/GitHub/sift/node_modules/@octokit/auth-app/node_modules/universal-github-app-jwt/dist-src/index.js:14:25)
              at getAppAuthentication (/Users/udbhavagarwal/Documents/GitHub/sift/node_modules/@octokit/auth-app/dist-node/index.js:53:73)
              at getInstallationAuthentication (/Users/udbhavagarwal/Documents/GitHub/sift/node_modules/@octokit/auth-app/dist-node/index.js:227:35)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at hook (/Users/udbhavagarwal/Documents/GitHub/sift/node_modules/@octokit/auth-app/dist-node/index.js:393:32)
              at _GithubMessageHandlerImpl.forward (/Users/udbhavagarwal/Documents/GitHub/sift/apps/ticketing/src/lib/github/github-message-handler.ts:66:21)
              at broadcastMessage (/Users/udbhavagarwal/Documents/GitHub/sift/apps/ticketing/src/lib/constructs/broadcast-message.ts:67:5)
              at Object.handle (/Users/udbhavagarwal/Documents/GitHub/sift/apps/ticketing/src/lib/slack/interactions/send-to-sift-shortcut.ts:48:5)`

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Udbhav8 Udbhav8 added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Aug 25, 2023
@ghost ghost added this to Bugs in JS Aug 25, 2023
@github-actions
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 labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@Udbhav8 Udbhav8 changed the title [BUG]: [BUG]: app.getInstallationOctokit() throws error Aug 25, 2023
@wolfy1339
Copy link
Member

Are you using ES Modules by chance? Can you share your tsconfig.json? Are you using a bundler?

@wolfy1339 wolfy1339 added Status: Needs info Full requirements are not yet known, so implementation should not be started and removed Status: Triage This is being looked at and prioritized labels Aug 26, 2023
@arturenault
Copy link

Hi - I'm working on this project with @Udbhav8.

  • We are using ES Modules
  • Here's out tsconfig.json:
{
  "compilerOptions": {
    "lib": ["es2023", "dom"],
    "module": "esnext",
    "target": "es2022",

    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "typeRoots": ["node_modules/@types", "./typings"],
    "isolatedModules": true,
    "noEmit": true
  },
}
  • We're using esbuild by way of SST. No custom options other than a few external modules

@wolfy1339
Copy link
Member

What I think happened is that SST is using the wrong package files, probably the dist-browser due to how the package.json defines the module field.

Is there a way you can force it to use dist-src directly instead of relying on what is defined in the package.json?

The build system it uses is no longer maintained, but the package was rewritten to ESM in v2 so it no longer uses that build system.

We're stuck with version 1 of that package unfortunately.

I don't know if it's worth changing the build system since v1 is only in maintenance releases

@wolfy1339
Copy link
Member

@Udbhav8 @arturenault Do you have any updates? Is this still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs info Full requirements are not yet known, so implementation should not be started Type: Bug Something isn't working as documented
Projects
Status: 🛑 Blocked/Awaiting Response
JS
  
Bugs
Development

No branches or pull requests

3 participants