auth-app.js: atob is not defined when building with target: Node using webpack

Hello,

I’m facing this error when I try to request the API. My project uses the following packages:

  • "@octokit/auth-app": "^2.4.4"
  • "@octokit/rest": "^17.1.4"
  • "typescript": "^3.8.2"
import { createAppAuth } from "@octokit/auth-app";
import { Octokit } from "@octokit/rest"

const appOctokit = new Octokit({
  authStrategy: createAppAuth,
  auth: {
    id: APP_ID,
    privateKey: PRIVATE_KEY
  }
})
const { data } = await appOctokit.request("/app");
console.log(data)
"errorType": "ReferenceError",
"errorMessage": "atob is not defined",
"stack": [
    "ReferenceError: atob is not defined",
    "    at getDERfromPEM (/var/task/webpack:/myapp/node_modules/universal-github-app-jwt/dist-web/index.js:15:1)",
    "    at getToken (/var/task/webpack:/myapp/node_modules/universal-github-app-jwt/dist-web/index.js:50:1)",
    "    at githubAppJwt (/var/task/webpack:/myapp/node_modules/universal-github-app-jwt/dist-web/index.js:71:1)",
    "    at getAppAuthentication (/var/task/webpack:/myapp/node_modules/@octokit/auth-app/dist-web/index.js:8:37)",
    "    at getInstallationAuthentication (/var/task/webpack:/myapp/node_modules/@octokit/auth-app/dist-web/index.js:110:1)",
    "    at dist_web_hook (/var/task/webpack:/myapp/node_modules/@octokit/auth-app/dist-web/index.js:240:20)",
    ...
]

I tried to install the package atob-lite cause it was a dependency in the past https://github.com/octokit/rest.js/pull/1302, but it doesn’t fix the issue.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Thank you for the explanation and the links. I will take the time to read the discussion and test the different workarounds. I very appreciated your help ⛑️ and your reactivity! A big THANK YOU for all your contributions to the open-source community πŸ‘

Did you ever find a workaround for this?

Thank you for the explanation and the links. I will take the time to read the discussion and test the different workarounds. I very appreciated your help ⛑️ and your reactivity! A big THANK YOU for all your contributions to the open-source community πŸ‘

@gr2m yes I think we can close it. Also in recent nodejs release (v16) atob is expose as global https://github.com/nodejs/node/pull/37786 so it probably fixes (in a way) the issue.

This issue https://github.com/webpack/webpack/issues/5756 could explain why my app is using the code under dist-web and not dist-node.

I tested this https://github.com/webpack/webpack/issues/5756#issuecomment-405468106 and it loads the correct code, but it’s not an option because it introduces potential side effects πŸ˜•

I tried to downgrade to β€œ@octokit/auth-app”: β€œ^2.0.1” (so before introducing the browser compatibility) and I can execute the code without issue.