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

Fixing fetch-polyfill (node-fetch) according to the documentation #462

Open
wants to merge 4 commits into
base: version-7.x
Choose a base branch
from

Conversation

qmachard
Copy link
Contributor

Hi !

Context

  • Node v16.15.0
  • NextJS v13.1.2
  • Typescript v4.6.4

Problem

Failed to provide global access to fetch in NextJS. Because global.fetch is already defined, and is in read only mode.

TypeError: Cannot set property Request of #<Object> which has only a getter

Solution

According to node-fetch documentation, simply adding a condition around the polyfill.

Cf. https://github.com/node-fetch/node-fetch#providing-global-access

if (!globalThis.fetch) {
  globalThis.fetch = fetch
  globalThis.Headers = Headers
  globalThis.Request = Request
  globalThis.Response = Response
}

Please, if you can merge this and release a new version of 7.x of ketting 🙏

Many Thanks
Quentin

@qmachard qmachard changed the title 🩹 Fixing fetch-polyfill (node-fetch) according to the documentation Fixing fetch-polyfill (node-fetch) according to the documentation Jan 19, 2023
@evert
Copy link
Collaborator

evert commented Jan 19, 2023

Hey, this looks reasonable... but a bit scary. The Javascript module world is weird and I'm slightly worried I might break something for someone else.

If I were to release an 8.x alpha version would that also work for you? This version simply no longer ships node-fetch or the polyfill.

@qmachard
Copy link
Contributor Author

Hi, I understand this problem...

I saw in next version that this polyfill is removed. I can try ketting 8.x, have you got a changelog or breaking changes list for this next version ?

Thanks,
Quentin

@evert
Copy link
Collaborator

evert commented Mar 1, 2023

hi @qmachard , this is the full list of changes so far for 8.x:

  • BC break: Dropped node-fetch dependency, because modern Node versions now
    provide a fetch function. If you want support for older Node versions,
    provide your own polyfill.
  • Support for versions older than Node 18 dropped.
  • Submitting actions with missing required fields will now throw an exception.
  • Actions that have pre-filled values will auto submit those values unless they
    are explicitly overridden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants