diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index 5e5dac938b8da..e03721527c606 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -1,3 +1,4 @@ +import '../server/node-polyfill-fetch' import chalk from 'next/dist/compiled/chalk' import getGzipSize from 'next/dist/compiled/gzip-size' import textTable from 'next/dist/compiled/text-table' diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index 251a4c01eb8af..9480ee488c924 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -1,3 +1,4 @@ +import './node-polyfill-fetch' import type { Params, Route } from './router' import type { CacheFs } from '../shared/lib/utils' import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plugin' diff --git a/test/production/required-server-files/pages/api/optional/[[...rest]].js b/test/production/required-server-files/pages/api/optional/[[...rest]].js index a5395a602d14c..ad5e9c26fb695 100644 --- a/test/production/required-server-files/pages/api/optional/[[...rest]].js +++ b/test/production/required-server-files/pages/api/optional/[[...rest]].js @@ -1,7 +1,9 @@ -export default (req, res) => { +export default async (req, res) => { console.log(req.url, 'query', req.query) res.json({ url: req.url, query: req.query, + // make sure fetch if polyfilled + example: await fetch('https://example.com').then((res) => res.text()), }) } diff --git a/test/production/required-server-files/pages/fallback/[slug].js b/test/production/required-server-files/pages/fallback/[slug].js index 518e2e10cafc6..f4d7c5a593829 100644 --- a/test/production/required-server-files/pages/fallback/[slug].js +++ b/test/production/required-server-files/pages/fallback/[slug].js @@ -10,7 +10,10 @@ export const getStaticProps = ({ params }) => { } } -export const getStaticPaths = () => { +export const getStaticPaths = async () => { + // make sure fetch if polyfilled + await fetch('https://example.com').then((res) => res.text()) + return { paths: ['/fallback/first'], fallback: true, diff --git a/test/production/required-server-files/pages/gssp.js b/test/production/required-server-files/pages/gssp.js index 210d482a90437..653736f016f41 100644 --- a/test/production/required-server-files/pages/gssp.js +++ b/test/production/required-server-files/pages/gssp.js @@ -19,6 +19,8 @@ export async function getServerSideProps({ res }) { props: { hello: 'world', data, + // make sure fetch if polyfilled + example: await fetch('https://example.com').then((res) => res.text()), }, } }