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

next/node-polyfill-web-streams: fix web stream polyfill for Node v16 #51901

Merged
merged 2 commits into from Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/next/src/server/node-polyfill-web-streams.ts
@@ -1,11 +1,22 @@
// Polyfill Web Streams for the Node.js runtime.
if (!global.ReadableStream) {
const { ReadableStream } =
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill')
global.ReadableStream = ReadableStream
// In Node v16, ReadableStream is available natively but under the `stream` namespace.
// In Node v18+, it's available under global.
if (require('stream').ReadableStream) {
global.ReadableStream = require('stream').ReadableStream
} else {
const { ReadableStream } =
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill')
global.ReadableStream = ReadableStream
}
}
if (!global.TransformStream) {
const { TransformStream } =
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill')
global.TransformStream = TransformStream
// Same as ReadableStream above.
if (require('stream').TransformStream) {
global.TransformStream = require('stream').TransformStream
} else {
const { TransformStream } =
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill')
global.TransformStream = TransformStream
}
}