Commit 164ccd1c authored by Jimmy Lai's avatar Jimmy Lai

tree shake correctly

parent 22c23392
...@@ -1055,5 +1055,6 @@ ...@@ -1055,5 +1055,6 @@
"1054": "processNodePrelude is not supported in edge runtime", "1054": "processNodePrelude is not supported in edge runtime",
"1055": "createUnclosingNodeStream is not supported in edge runtime", "1055": "createUnclosingNodeStream is not supported in edge runtime",
"1056": "createClosingNodeStream is not supported in edge runtime", "1056": "createClosingNodeStream is not supported in edge runtime",
"1057": "Cannot tee a Node.js stream in the edge runtime" "1057": "Cannot tee a Node.js stream in the edge runtime",
"1058": "toNodeDebugChannel can only be used in Node.js environments, this is a bug in the Next.js codebase"
} }
...@@ -25,6 +25,12 @@ export type DebugChannelClient = { ...@@ -25,6 +25,12 @@ export type DebugChannelClient = {
export function toNodeDebugChannel( export function toNodeDebugChannel(
webDebugChannel: DebugChannelServer webDebugChannel: DebugChannelServer
): import('node:stream').Writable { ): import('node:stream').Writable {
// Guard so webpack can DCE node:stream require for edge builds.
if (!process.env.__NEXT_USE_NODE_STREAMS) {
throw new Error(
'toNodeDebugChannel can only be used in Node.js environments, this is a bug in the Next.js codebase'
)
} else {
const { Writable } = require('node:stream') as typeof import('node:stream') const { Writable } = require('node:stream') as typeof import('node:stream')
const writer = webDebugChannel.writable.getWriter() const writer = webDebugChannel.writable.getWriter()
return new Writable({ return new Writable({
...@@ -45,6 +51,7 @@ export function toNodeDebugChannel( ...@@ -45,6 +51,7 @@ export function toNodeDebugChannel(
) )
}, },
}) })
}
} }
export function createDebugChannel(): DebugChannelPair | undefined { export function createDebugChannel(): DebugChannelPair | undefined {
......
...@@ -156,7 +156,10 @@ export function renderToFlightPipeableStream( ...@@ -156,7 +156,10 @@ export function renderToFlightPipeableStream(
if (options?.debugChannel) { if (options?.debugChannel) {
const { toNodeDebugChannel } = const { toNodeDebugChannel } =
require('./debug-channel-server') as typeof import('./debug-channel-server') require('./debug-channel-server') as typeof import('./debug-channel-server')
options = { ...options, debugChannel: toNodeDebugChannel(options.debugChannel) } options = {
...options,
debugChannel: toNodeDebugChannel(options.debugChannel),
}
} }
const { pipe } = renderToPipeableStreamFn(model, webpackMap, options) const { pipe } = renderToPipeableStreamFn(model, webpackMap, options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment