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]: unable to use this package with @actions/github-script #499

Closed
1 task done
shaneholder opened this issue Jun 19, 2023 · 19 comments
Closed
1 task done

[BUG]: unable to use this package with @actions/github-script #499

shaneholder opened this issue Jun 19, 2023 · 19 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@shaneholder
Copy link

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/[email protected] 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
@shaneholder shaneholder added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented, or is being fixed labels Jun 19, 2023
@wolfy1339
Copy link
Member

wolfy1339 commented Jun 19, 2023

What version of Node JS is it running under? We dropped support for anything lower than Node v18 in v5.0.0, and we also stopped using node-fetch to instead use the Fetch API.

@wolfy1339 wolfy1339 added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Bug Something isn't working as documented, or is being fixed Status: Triage This is being looked at and prioritized labels Jun 19, 2023
wolfy1339 added a commit to octokit/request.js that referenced this issue Jun 20, 2023
For some reason, clients are not getting the updated version of `@octokit/endpoint` via other packages that require `@octokit/request`

See octokit/auth-app.js#499
@wolfy1339 wolfy1339 moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Jun 20, 2023
@JMoserCricut
Copy link

JMoserCricut commented Jun 20, 2023

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

@wolfy1339
Copy link
Member

That's odd. You need to pass a fetch API polyfill, like node-fetch because it seems that the fetch API is disabled on the version of node you use

@JMoserCricut
Copy link

@wolfy1339 As @shaneholder pointed out the update to the request.js (which includes breaking changes) should've marked this v5.0.5 release as a breaking change rather than a patch change. I suggest that the v5.0.5 be reverted and re-released as a major change release since it includes breaking changes

@wolfy1339
Copy link
Member

v5 dropped support for Node JS v14, 16.

The fetch API is included in Node 18, hence it's not a breaking change.

@JMoserCricut
Copy link

My screenshots seem to tell a different story, the first one is where I installed with node 18 running v5.0.5 of the auth-app, the result shows that there is no fetch found. We're using the setup node action to install node 18

@wolfy1339
Copy link
Member

I can't reproduce it locally. Node 18 has the fetch api

@wolfy1339
Copy link
Member

It could be disabled in the builds they use, as it's still marked as experimental

https://nodejs.org/en/blog/announcements/v18-release-announce

@wolfy1339
Copy link
Member

That shouldn't be the case, as we use GitHub actions with setup-node and it works just fine

@JMoserCricut
Copy link

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

gr2m pushed a commit to octokit/request.js that referenced this issue Jun 20, 2023
For some reason, clients are not getting the updated version of `@octokit/endpoint` via other packages that require `@octokit/request`

See octokit/auth-app.js#499
@shaneholder
Copy link
Author

Can confirm, I am also using github-script.

@wolfy1339 wolfy1339 changed the title [BUG]: V5.0.5 throws exception when using @octokit/auth-app [BUG]: unable to use this package with @actions/github-script Jun 21, 2023
hudeng-go added a commit to hudeng-go/.github that referenced this issue Jul 12, 2023
fix by config nodejs version to 18

Issue: octokit/auth-app.js#499
deepin-ci-robot pushed a commit to deepin-community/.github that referenced this issue Jul 12, 2023
fix by config nodejs version to 18

Issue: octokit/auth-app.js#499
@myml
Copy link

myml commented Jul 12, 2023

fetch not in global object, add global["fetch"] = fetch to the first line of script can fix it.

@wolfy1339
Copy link
Member

fetch not in global object, add global["fetch"] = fetch to the first line of script can fix it.

That is not a sensible solution.

Simply pass a fetch polyfill in options.request.fetch

@wolfy1339
Copy link
Member

The newer versions of this package are incompatible with @actions/github-script since it does not have Node 18.

There is nothing for us to do here

@wolfy1339 wolfy1339 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Jul 12, 2023
@chandrakanthbala
Copy link

I'm facing the same issue. Can someone please let me know what is the resolution for this with below configuration?

Runner: ubuntu-latest
Node Version On Runner: 18.16.1
Using: actions/[email protected]

@chandrakanthbala
Copy link

@wolfy1339 How to pass a fetch polyfill in options.request.fetch?

@KevinMSampson
Copy link

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/[email protected] @octokit/[email protected]
        run: |
          npm install @octokit/[email protected] @octokit/[email protected]
...

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/[email protected] wasn't enough.

@chandrakanthbala
Copy link

@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/[email protected] @octokit/[email protected]
        run: |
          npm install @octokit/[email protected] @octokit/[email protected]
...

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/[email protected] wasn't enough.

@KevinMSampson Thanks Kevin 😃

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Archived in project
Development

No branches or pull requests

7 participants