[BUG]: Error being thrown when trying to authenticate with v8.0.2
Opened this issue ยท 7 comments
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
๐ 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! ๐
Are you using ESM in your code?
Are you using ESM in your code?
Yes I am, my bad for not mentioning it in the original post
I can't reproduce it myself
This is the joys of the ESM migration ๐
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"
}
}
},
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();
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";