Unverified Commit 9477b61b authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

fix(next): clarify `fetch` polyfill, drop `node-fetch` (#53548)

### What?

Fix documentation about `fetch` polyfilling, and drop `node-fetch` references.

### Why?

Since we stopped using `node-fetch` in `next` in favor of `undici` there were some inconsistencies in the docs, and unused references to the `node-fetch` package inside `packages/next`-


Noted this while answering this [Slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1691089801007129)
parent bf9c65f8
...@@ -5,7 +5,7 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo ...@@ -5,7 +5,7 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [node-fetch](/docs/architecture/supported-browsers#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [undici](/docs/architecture/supported-browsers#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default.
To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config: To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config:
......
...@@ -59,7 +59,7 @@ Next.js allows you to use the latest JavaScript features out of the box. In addi ...@@ -59,7 +59,7 @@ Next.js allows you to use the latest JavaScript features out of the box. In addi
### Server-Side Polyfills ### Server-Side Polyfills
In addition to `fetch()` on the client-side, Next.js polyfills `fetch()` in the Node.js environment. You can use `fetch()` in your server code (such as `getStaticProps`/`getServerSideProps`) without using polyfills such as `isomorphic-unfetch` or `node-fetch`. In addition to `fetch()` on the client-side, Next.js polyfills `fetch()` in the Node.js environment where it's not yet available. It uses `undici`, the same implementation that Node.js itself uses. You can use `fetch()` in your server code (such as `getStaticProps`/`getServerSideProps`) without using polyfills such as `isomorphic-unfetch` or `node-fetch`.
### TypeScript Features ### TypeScript Features
......
...@@ -168,7 +168,6 @@ ...@@ -168,7 +168,6 @@
"@types/lodash.curry": "4.1.6", "@types/lodash.curry": "4.1.6",
"@types/lru-cache": "5.1.0", "@types/lru-cache": "5.1.0",
"@types/micromatch": "4.0.2", "@types/micromatch": "4.0.2",
"@types/node-fetch": "2.6.1",
"@types/path-to-regexp": "1.7.0", "@types/path-to-regexp": "1.7.0",
"@types/platform": "1.3.4", "@types/platform": "1.3.4",
"@types/react": "18.2.5", "@types/react": "18.2.5",
...@@ -249,7 +248,6 @@ ...@@ -249,7 +248,6 @@
"nanoid": "3.1.32", "nanoid": "3.1.32",
"native-url": "0.3.4", "native-url": "0.3.4",
"neo-async": "2.6.1", "neo-async": "2.6.1",
"node-fetch": "2.6.7",
"node-html-parser": "5.3.3", "node-html-parser": "5.3.3",
"ora": "4.0.4", "ora": "4.0.4",
"os-browserify": "0.3.0", "os-browserify": "0.3.0",
......
...@@ -540,10 +540,10 @@ export interface NextConfig extends Record<string, any> { ...@@ -540,10 +540,10 @@ export interface NextConfig extends Record<string, any> {
serverRuntimeConfig?: { [key: string]: any } serverRuntimeConfig?: { [key: string]: any }
/** /**
* Next.js automatically polyfills node-fetch and enables HTTP Keep-Alive by default. * Next.js enables HTTP Keep-Alive by default.
* You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally. * You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally.
* *
* @see [Disabling HTTP Keep-Alive](https://nextjs.org/docs/api-reference/next.config.js/disabling-http-keep-alive) * @see [Disabling HTTP Keep-Alive](https://nextjs.org/docs/app/api-reference/next-config-js/httpAgentOptions)
*/ */
httpAgentOptions?: { keepAlive?: boolean } httpAgentOptions?: { keepAlive?: boolean }
......
...@@ -136,7 +136,6 @@ export function loadWebpackHook() { ...@@ -136,7 +136,6 @@ export function loadWebpackHook() {
'@babel/runtime/package.json', '@babel/runtime/package.json',
'next/dist/compiled/@babel/runtime/package.json', 'next/dist/compiled/@babel/runtime/package.json',
], ],
['node-fetch', 'next/dist/compiled/node-fetch'],
['undici', 'next/dist/compiled/undici'], ['undici', 'next/dist/compiled/undici'],
].map( ].map(
// Use dynamic require.resolve to avoid statically analyzable since they're only for build time // Use dynamic require.resolve to avoid statically analyzable since they're only for build time
......
...@@ -41,12 +41,6 @@ declare module 'next/dist/compiled/node-html-parser' { ...@@ -41,12 +41,6 @@ declare module 'next/dist/compiled/node-html-parser' {
export * from 'node-html-parser' export * from 'node-html-parser'
} }
declare module 'next/dist/compiled/node-fetch' {
import m from 'node-fetch'
export default m
export * from 'node-fetch'
}
declare module 'next/dist/compiled/undici' {} declare module 'next/dist/compiled/undici' {}
declare module 'next/dist/compiled/jest-worker' { declare module 'next/dist/compiled/jest-worker' {
......
...@@ -540,7 +540,6 @@ importers: ...@@ -540,7 +540,6 @@ importers:
'@types/lodash.curry': 4.1.6 '@types/lodash.curry': 4.1.6
'@types/lru-cache': 5.1.0 '@types/lru-cache': 5.1.0
'@types/micromatch': 4.0.2 '@types/micromatch': 4.0.2
'@types/node-fetch': 2.6.1
'@types/path-to-regexp': 1.7.0 '@types/path-to-regexp': 1.7.0
'@types/platform': 1.3.4 '@types/platform': 1.3.4
'@types/react': 18.2.7 '@types/react': 18.2.7
...@@ -623,7 +622,6 @@ importers: ...@@ -623,7 +622,6 @@ importers:
nanoid: 3.1.32 nanoid: 3.1.32
native-url: 0.3.4 native-url: 0.3.4
neo-async: 2.6.1 neo-async: 2.6.1
node-fetch: 2.6.7
node-html-parser: 5.3.3 node-html-parser: 5.3.3
ora: 4.0.4 ora: 4.0.4
os-browserify: 0.3.0 os-browserify: 0.3.0
...@@ -760,7 +758,6 @@ importers: ...@@ -760,7 +758,6 @@ importers:
'@types/lodash.curry': 4.1.6 '@types/lodash.curry': 4.1.6
'@types/lru-cache': 5.1.0 '@types/lru-cache': 5.1.0
'@types/micromatch': 4.0.2 '@types/micromatch': 4.0.2
'@types/node-fetch': 2.6.1
'@types/path-to-regexp': 1.7.0 '@types/path-to-regexp': 1.7.0
'@types/platform': 1.3.4 '@types/platform': 1.3.4
'@types/react': 18.2.7 '@types/react': 18.2.7
...@@ -841,7 +838,6 @@ importers: ...@@ -841,7 +838,6 @@ importers:
nanoid: 3.1.32 nanoid: 3.1.32
native-url: 0.3.4 native-url: 0.3.4
neo-async: 2.6.1 neo-async: 2.6.1
node-fetch: 2.6.7
node-html-parser: 5.3.3 node-html-parser: 5.3.3
ora: 4.0.4 ora: 4.0.4
os-browserify: 0.3.0 os-browserify: 0.3.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment