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]: Error being thrown when trying to authenticate with v8.0.2 #428

Open
1 task done
dscotland opened this issue Mar 7, 2024 · 7 comments
Open
1 task done
Labels
Type: Bug Something isn't working as documented

Comments

@dscotland
Copy link

What happened?

What did I do:
I'm trying to import and use @octokit/auth-oauth-app to handle Github user authentication in an AWS Lambda function.

What happened:
I was able to trigger the lambda function but got the following error message: No \"exports\" main defined in /var/task/node_modules/@octokit/auth-oauth-app/package.json

What did I expect:
I was expecting to be able to trigger the lambda, successfully authenticate and perform other actions using the access_token I'd have received from the authentication.

Versions

Octokit version: 8.0.2

Node version: 18.17

Relevant log output

{
    "errorType": "Error",
    "errorMessage": "No \"exports\" main defined in /var/task/node_modules/@octokit/auth-oauth-app/package.json",
    "code": "ERR_PACKAGE_PATH_NOT_EXPORTED",
    "stack": [
        "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No \"exports\" main defined in /var/task/node_modules/@octokit/auth-oauth-app/package.json",
        "    at new NodeError (node:internal/errors:405:5)",
        "    at exportsNotFound (node:internal/modules/esm/resolve:371:10)",
        "    at packageExportsResolve (node:internal/modules/esm/resolve:661:13)",
        "    at resolveExports (node:internal/modules/cjs/loader:584:36)",
        "    at Module._findPath (node:internal/modules/cjs/loader:658:31)",
        "    at Module._resolveFilename (node:internal/modules/cjs/loader:1120:27)",
        "    at Module._load (node:internal/modules/cjs/loader:975:27)",
        "    at Module.require (node:internal/modules/cjs/loader:1225:19)",
        "    at require (node:internal/modules/helpers:177:18)",
        "    at Object.<anonymous> (/var/task/lib/application/utilitiesService/handler/utilities.js:29:26)"
    ]
}

Code of Conduct

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

github-actions bot commented Mar 7, 2024

👋 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! 🚀

@wolfy1339
Copy link
Member

Are you using ESM in your code?

@dscotland
Copy link
Author

Are you using ESM in your code?

Yes I am, my bad for not mentioning it in the original post

@wolfy1339
Copy link
Member

I can't reproduce it myself
This is the joys of the ESM migration 😓

@wolfy1339 wolfy1339 removed the Status: Triage This is being looked at and prioritized label Mar 7, 2024
@wolfy1339
Copy link
Member

Can you try modifying the package.json for @octokit/auth-oauth-app like so by replacing the fields with the following:

  "module": "./dist-node/index.js",
  "types": "./dist-types/index.d.ts",
  "exports": {
    ".": {
      "import": {
        "types": "./dist-types/index.d.ts",
        "default": "./dist-node/index.js"
      }
    }
  },

@dscotland
Copy link
Author

I can't reproduce it myself This is the joys of the ESM migration 😓

We tried reproducing it with a simple JS script and were able to do so as well. It was essentially this:

const { createOAuthAppAuth } = require("@octokit/auth-oauth-app");

async function test() {
  const auth = createOAuthAppAuth({
    clientType: "oauth-app",
    clientId: "1234567890abcdef1234",
    clientSecret: "1234567890abcdef1234567890abcdef12345678",
  });
  const appAuthentication = await auth({
    type: "oauth-app",
  });
  console.log({appAuthentication});
}
test();

@wolfy1339
Copy link
Member

You are using the wrong kind of import there, that's a CJS import https://blog.logrocket.com/commonjs-vs-es-modules-node-js/

import { createOAuthAppAuth } from "@octokit/auth-oauth-app";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants