diff --git a/packages/next/src/server/dev/hot-middleware.ts b/packages/next/src/server/dev/hot-middleware.ts index 7753f5742747f..2a2e52001e765 100644 --- a/packages/next/src/server/dev/hot-middleware.ts +++ b/packages/next/src/server/dev/hot-middleware.ts @@ -22,7 +22,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import type { webpack } from 'next/dist/compiled/webpack/webpack' -import type ws from 'ws' +import type ws from 'next/dist/compiled/ws' import { isMiddlewareFilename } from '../../build/utils' import type { VersionInfo } from './parse-version-info' diff --git a/packages/next/src/server/dev/on-demand-entry-handler.ts b/packages/next/src/server/dev/on-demand-entry-handler.ts index ccded09385031..d510b5b7d40a5 100644 --- a/packages/next/src/server/dev/on-demand-entry-handler.ts +++ b/packages/next/src/server/dev/on-demand-entry-handler.ts @@ -1,4 +1,4 @@ -import type ws from 'ws' +import type ws from 'next/dist/compiled/ws' import origDebug from 'next/dist/compiled/debug' import type { webpack } from 'next/dist/compiled/webpack/webpack' import type { NextConfigComplete } from '../config-shared' diff --git a/packages/next/src/server/node-environment.ts b/packages/next/src/server/node-environment.ts index ad2119eb2bf7c..5e177e33c822d 100644 --- a/packages/next/src/server/node-environment.ts +++ b/packages/next/src/server/node-environment.ts @@ -8,14 +8,5 @@ if (typeof (globalThis as any).AsyncLocalStorage !== 'function') { } if (typeof (globalThis as any).WebSocket !== 'function') { - let WebSocket - - // undici's WebSocket handling is only available in Node.js >= 18 - // so fallback to using ws for v16 - if (Number(process.version.split('.')[0].substring(1)) < 18) { - WebSocket = require('next/dist/compiled/ws').WebSocket - } else { - WebSocket = require('next/dist/compiled/undici').WebSocket - } - ;(globalThis as any).WebSocket = WebSocket + ;(globalThis as any).WebSocket = require('next/dist/compiled/ws').WebSocket } diff --git a/packages/next/src/server/web/sandbox/context.ts b/packages/next/src/server/web/sandbox/context.ts index 3d75227faa02f..96d788a31e0a5 100644 --- a/packages/next/src/server/web/sandbox/context.ts +++ b/packages/next/src/server/web/sandbox/context.ts @@ -235,17 +235,7 @@ async function createModuleContext(options: ModuleContextOptions) { ? { strings: true, wasm: true } : undefined, extend: (context) => { - let WebSocket - - // undici's WebSocket handling is only available in Node.js >= 18 - // so fallback to using ws for v16 - if (Number(process.version.split('.')[0].substring(1)) < 18) { - WebSocket = require('next/dist/compiled/ws').WebSocket - } else { - WebSocket = require('next/dist/compiled/undici').WebSocket - } - - context.WebSocket = WebSocket + context.WebSocket = require('next/dist/compiled/ws').WebSocket context.process = createProcessPolyfill(options) Object.defineProperty(context, 'require', {