-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
40 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
// Polyfill Web Streams for the Node.js runtime. | ||
if (!global.ReadableStream) { | ||
// In Node v16, ReadableStream is available natively but under the `stream` namespace. | ||
// In Node v18+, it's available under global. | ||
if (require('stream/web').ReadableStream) { | ||
global.ReadableStream = require('stream/web').ReadableStream | ||
} else { | ||
const { ReadableStream } = | ||
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill') | ||
global.ReadableStream = ReadableStream | ||
if (process.env.NEXT_RUNTIME !== 'edge') { | ||
// Polyfill Web Streams for the Node.js runtime. | ||
if (!global.ReadableStream) { | ||
// In Node v16, ReadableStream is available natively but under the `stream` namespace. | ||
// In Node v18+, it's available under global. | ||
if (require('stream/web').ReadableStream) { | ||
global.ReadableStream = require('stream/web').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.WritableStream) { | ||
// In Node v16, WritableStream is available natively but under the `stream` namespace. | ||
// In Node v18+, it's available under global. | ||
if (require('stream/web').WritableStream) { | ||
global.WritableStream = require('stream/web').WritableStream | ||
} else { | ||
const { WritableStream } = | ||
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill') | ||
global.WritableStream = WritableStream | ||
if (!global.WritableStream) { | ||
// In Node v16, WritableStream is available natively but under the `stream` namespace. | ||
// In Node v18+, it's available under global. | ||
if (require('stream/web').WritableStream) { | ||
global.WritableStream = require('stream/web').WritableStream | ||
} else { | ||
const { WritableStream } = | ||
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill') | ||
global.WritableStream = WritableStream | ||
} | ||
} | ||
} | ||
if (!global.TransformStream) { | ||
// Same as ReadableStream above. | ||
if (require('stream/web').TransformStream) { | ||
global.TransformStream = require('stream/web').TransformStream | ||
} else { | ||
const { TransformStream } = | ||
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill') | ||
global.TransformStream = TransformStream | ||
if (!global.TransformStream) { | ||
// Same as ReadableStream above. | ||
if (require('stream/web').TransformStream) { | ||
global.TransformStream = require('stream/web').TransformStream | ||
} else { | ||
const { TransformStream } = | ||
require('next/dist/compiled/@edge-runtime/ponyfill') as typeof import('next/dist/compiled/@edge-runtime/ponyfill') | ||
global.TransformStream = TransformStream | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/next/src/server/stream-utils/node-web-streams-helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters