auth-app.js: [BUG]: unable to use this package with `@actions/github-script`

What happened?

It looks like between 5.0.4 and 5.0.5 dependencies were updated. I suspect that the upgrade from @octokit/request 6.0.0 to 7.0.0 may have caused this issue.

The following code throws an error in 5.0.5 when run under actions/github-script@v6

const { createAppAuth } = require("@octokit/auth-app");
const key = `${{ secrets.PrivKey }}`

var auth = createAppAuth({appId: "${{vars.APPID}}", privateKey: key });            
var authentication = await auth({type: "installation", installationId: "${{vars.INSTALLID}}" })

return authentication.token  

Error:

Error: Global "fetch" not found. Please provide `options.request.fetch` to octokit or upgrade to node@18 or newer.
    at fetchWrapper (/home/runner/work/tf-project/tf-project/node_modules/@octokit/request/dist-node/index.js:56:11)
    at newApi (/home/runner/work/tf-project/tf-project/node_modules/@octokit/request/dist-node/index.js:176:14)
    at getInstallationAuthentication (/home/runner/work/tf-project/tf-project/node_modules/@octokit/auth-app/dist-node/index.js:238:13)
    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16), <anonymous>:34:[22](https://github.com/sah-test/tf-project/actions/runs/5316189964/jobs/9625440887#step:4:23))
    at async main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15[23](https://github.com/sah-test/tf-project/actions/runs/5316189964/jobs/9625440887#step:4:24)6:20)
Error: Unhandled error: Error: Global "fetch" not found. Please provide `options.request.fetch` to octokit or upgrade to node@18 or newer.

Makes me also wonder if the semver should be bumped by a major version if dependencies are bumped by a major version…

Thanks, Shane

Versions

@octokit/auth-app@5.0.5 actions/github-script@v6

Relevant log output

Run actions/github-script@v6
  with:
    script: const { createAppAuth } = require("@octokit/auth-app");
  const key = `***
  `
  
  var auth = createAppAuth({appId: "***", privateKey: key });            
  var authentication = await auth({type: "installation", installationId: "***" })
  
  return authentication.token  
  
    github-token: ***
    debug: false
    user-agent: actions/github-script
    result-encoding: json
    retries: 0
    retry-exempt-status-codes: 400,401,403,404,422
  env:
    WORKING_DIR: .
    ENVIRONMENT: development
Error: Global "fetch" not found. Please provide `options.request.fetch` to octokit or upgrade to node@18 or newer.
    at fetchWrapper (/home/runner/work/tf-project/tf-project/node_modules/@octokit/request/dist-node/index.js:56:11)
    at newApi (/home/runner/work/tf-project/tf-project/node_modules/@octokit/request/dist-node/index.js:176:14)
    at getInstallationAuthentication (/home/runner/work/tf-project/tf-project/node_modules/@octokit/auth-app/dist-node/index.js:238:13)
    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16), <anonymous>:34:22)
    at async main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:20)
Error: Unhandled error: Error: Global "fetch" not found. Please provide `options.request.fetch` to octokit or upgrade to node@18 or newer.

Code of Conduct

  • I agree to follow this project’s Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@KevinMSampson Thanks Kevin 😃

I misread that and didn’t pin the Node version to 16. This solved the issue.

yes this is still an issue with node 18: image pinning to v5.0.4 resolves the issue for us, even using node 16… image

@chandrakanthbala This reply has a good example

     - uses: actions/setup-node@v3
        with:
          node-version: 16
      
      # NOTE: Temporary fix - https://github.com/octokit/auth-app.js/issues/499#issuecomment-1599121855
      - name: npm install @octokit/rest@v19.0.13 @octokit/auth-app@v5.0.4
        run: |
          npm install @octokit/rest@v19.0.13 @octokit/auth-app@v5.0.4
...

I noticed that since I follow the octokit document example using @octokit/rest too, I made sure to pin to an older version of that too. Pinning @octokit/auth-app@v5.0.4 wasn’t enough.

@KevinMSampson Thanks Kevin 😃

I misread that and didn’t pin the Node version to 16. This solved the issue.

Can confirm, I am also using github-script.

I think it may be that both @shaneholder and I are using the octokit/auth-app wrapped within the actions/github-script which provides it’s own reference to fetch and only supports up to node 16 it seems