Skip to content

Commit e8c15e5

Browse files
authoredJan 24, 2022
Ensure fetch polyfill is loaded in next-server (#33616)
1 parent 9a2d97c commit e8c15e5

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed
 

‎packages/next/build/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../server/node-polyfill-fetch'
12
import chalk from 'next/dist/compiled/chalk'
23
import getGzipSize from 'next/dist/compiled/gzip-size'
34
import textTable from 'next/dist/compiled/text-table'

‎packages/next/server/next-server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './node-polyfill-fetch'
12
import type { Params, Route } from './router'
23
import type { CacheFs } from '../shared/lib/utils'
34
import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plugin'
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
export default (req, res) => {
1+
export default async (req, res) => {
22
console.log(req.url, 'query', req.query)
33
res.json({
44
url: req.url,
55
query: req.query,
6+
// make sure fetch if polyfilled
7+
example: await fetch('https://example.com').then((res) => res.text()),
68
})
79
}

‎test/production/required-server-files/pages/fallback/[slug].js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export const getStaticProps = ({ params }) => {
1010
}
1111
}
1212

13-
export const getStaticPaths = () => {
13+
export const getStaticPaths = async () => {
14+
// make sure fetch if polyfilled
15+
await fetch('https://example.com').then((res) => res.text())
16+
1417
return {
1518
paths: ['/fallback/first'],
1619
fallback: true,

‎test/production/required-server-files/pages/gssp.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export async function getServerSideProps({ res }) {
1919
props: {
2020
hello: 'world',
2121
data,
22+
// make sure fetch if polyfilled
23+
example: await fetch('https://example.com').then((res) => res.text()),
2224
},
2325
}
2426
}

0 commit comments

Comments
 (0)
Please sign in to comment.