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

[DOCS]: global fetch warning is confusing #2495

Closed
1 task done
skeddles opened this issue Jul 12, 2023 · 7 comments
Closed
1 task done

[DOCS]: global fetch warning is confusing #2495

skeddles opened this issue Jul 12, 2023 · 7 comments
Labels
Type: Documentation Improvements or additions to documentation

Comments

@skeddles
Copy link

skeddles commented Jul 12, 2023

Describe the need

Error: Global "fetch" not found. Please provide options.request.fetch to octokit or upgrade to node@18 or newer.

const { Octokit } = require("octokit");
const nodefetch = import("node-fetch");
const octokit = new Octokit({ auth: KEY, request: {fetch: nodefetch.fetch} });
const { Octokit } = require("octokit");
global.fetch = import("node-fetch").fetch;
const octokit = new Octokit({ auth: KEY, request: {fetch: fetch} });
const { Octokit } = require("octokit");
const {fetch}= import("node-fetch");
const octokit = new Octokit({ auth: KEY, request: {fetch: fetch} });

I've tried every combination I can think of, and can't get it to work. Please provide a working example of how I am supposed to make this work.

SDK Version

No response

API Version

No response

Relevant log output

Error: Global "fetch" not found. Please provide `options.request.fetch` to octokit or upgrade to node@18 or newer.
    at fetchWrapper (/home/skeddles/azlador.com/node_modules/@octokit/request/dist-node/index.js:57:11)
    at request2 (/home/skeddles/azlador.com/node_modules/@octokit/request/dist-node/index.js:172:14)
    at hook (/home/skeddles/azlador.com/node_modules/@octokit/auth-token/dist-node/index.js:58:10)
    at async requestWithGraphqlErrorHandling (/home/skeddles/azlador.com/node_modules/octokit/node_modules/@octokit/plugin-retry/dist-node/index.js:71:20)
    at async Job.doExecute (/home/skeddles/azlador.com/node_modules/bottleneck/light.js:405:18)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@skeddles skeddles added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Jul 12, 2023
@wolfy1339
Copy link
Member

Please answer the following questions in order for us to help you:

  • What platform? Deno? Web? NodeJS?
  • What version of that platform?
  • What version of Octokit are you using?
  • What version of node-fetch?

@wolfy1339 wolfy1339 added Type: Bug Something isn't working as documented and removed Type: Feature New feature or request labels Jul 12, 2023
@skeddles
Copy link
Author

node
v16.17
^3.0.0 (latest)
^3.3.1 (latest)

@wolfy1339
Copy link
Member

That is the issue, we don't support Node JS 16 in version 3.x of Octokit

@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 Status: Triage This is being looked at and prioritized labels Jul 12, 2023
@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 🆕 Triage to ✅ Done in 🧰 Octokit Active Jul 12, 2023
@wolfy1339 wolfy1339 added Type: Documentation Improvements or additions to documentation and removed Type: Support Any questions, information, or general needs around the SDK or GitHub APIs labels Jul 12, 2023
@wolfy1339
Copy link
Member

I agree that the message might be confusing, reopening to track a possible wording of the message

@wolfy1339 wolfy1339 reopened this Jul 12, 2023
@wolfy1339 wolfy1339 changed the title [FEAT]: global fetch warning is confusing [DOCS]: global fetch warning is confusing Jul 12, 2023
@gr2m
Copy link
Contributor

gr2m commented Jul 12, 2023

you cannot combine require and import statements. If you use CommonJS (require), then install node-fetch@2 and try this

const { Octokit } = require("octokit");
const fetch = require("node-fetch");
const octokit = new Octokit({ auth: KEY, request: {fetch} });

But as @wolfy1339 mentioned, while this might work, we dropped official support for Node 16. Node 16 will no longer be maintained at all in two months: https://nodejs.dev/en/about/releases/.

@wolfy1339
Copy link
Member

Closing in favor of #2457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Documentation Improvements or additions to documentation
Projects
Archived in project
Development

No branches or pull requests

4 participants
@gr2m @skeddles @wolfy1339 and others