Skip to content

Ensure fetch polyfill is loaded in next-server #33616

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

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
1 change: 1 addition & 0 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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()),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions test/production/required-server-files/pages/gssp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
}
}
Expand Down