diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 77b438810519c..7af82942bcbb2 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -1,4 +1,7 @@ -import { join } from 'path' +import path from '../shared/lib/fallback/path' + +const { join } = path + export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..') export const NEXT_PROJECT_ROOT_DIST = join(NEXT_PROJECT_ROOT, 'dist') export const NEXT_PROJECT_ROOT_NODE_MODULES = join( diff --git a/packages/next/server/incremental-cache.ts b/packages/next/server/incremental-cache.ts index 7b4b1a8ad6e98..d1d463fba2e21 100644 --- a/packages/next/server/incremental-cache.ts +++ b/packages/next/server/incremental-cache.ts @@ -1,7 +1,7 @@ import type { CacheFs } from '../shared/lib/utils' import LRUCache from 'next/dist/compiled/lru-cache' -import path from 'path' +import path from '../shared/lib/fallback/path' import { PrerenderManifest } from '../build' import { normalizePagePath } from './normalize-page-path' import { IncrementalCacheValue, IncrementalCacheEntry } from './response-cache' diff --git a/packages/next/server/normalize-page-path.ts b/packages/next/server/normalize-page-path.ts index f9996331e3bec..943732f83eb3c 100644 --- a/packages/next/server/normalize-page-path.ts +++ b/packages/next/server/normalize-page-path.ts @@ -1,6 +1,8 @@ -import { posix } from 'path' +import path from '../shared/lib/fallback/path' import { isDynamicRoute } from '../shared/lib/router/utils' +const { posix } = path + export { normalizePathSep, denormalizePagePath } from './denormalize-page-path' export function normalizePagePath(page: string): string { diff --git a/packages/next/server/render.tsx b/packages/next/server/render.tsx index e42ccc75760e9..e1bfdc979507b 100644 --- a/packages/next/server/render.tsx +++ b/packages/next/server/render.tsx @@ -21,7 +21,6 @@ import type { GetServerSideProps, GetStaticProps, PreviewData } from '../types' import type { UnwrapPromise } from '../lib/coalesced-function' import React from 'react' -import { stringify as stringifyQuery } from 'querystring' import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack' import { renderToReadableStream } from 'next/dist/compiled/react-server-dom-webpack/writer.browser.server' import { StyleRegistry, createStyleRegistry } from 'styled-jsx' @@ -79,6 +78,7 @@ import { import { ImageConfigContext } from '../shared/lib/image-config-context' import { FlushEffectsContext } from '../shared/lib/flush-effects' import { interopDefault } from '../lib/interop-default' +import { urlQueryToSearchParams } from '../shared/lib/router/utils/querystring' let optimizeAmp: typeof import('./optimize-amp').default let getFontDefinitionFromManifest: typeof import('./font-utils').getFontDefinitionFromManifest @@ -518,7 +518,7 @@ export async function renderToHTML( if (isServerComponent) { serverComponentsInlinedTransformStream = new TransformStream() - const search = stringifyQuery(query) + const search = urlQueryToSearchParams(query).toString() Component = createServerComponentRenderer(AppMod, ComponentMod, { cachePrefix: pathname + (search ? `?${search}` : ''), inlinedTransformStream: serverComponentsInlinedTransformStream, diff --git a/packages/next/server/web-server.ts b/packages/next/server/web-server.ts index 2cc83dc9a2cdc..7f651a2fb442b 100644 --- a/packages/next/server/web-server.ts +++ b/packages/next/server/web-server.ts @@ -5,8 +5,9 @@ import type { NextParsedUrlQuery } from './request-meta' import type { Params } from './router' import type { PayloadOptions } from './send-payload' import type { LoadComponentsReturnType } from './load-components' +import type { Options } from './base-server' -import BaseServer, { Options } from './base-server' +import BaseServer from './base-server' import { renderToHTML } from './render' import { byteLength, generateETag } from './api-utils/web' diff --git a/packages/next/shared/lib/fallback/path.ts b/packages/next/shared/lib/fallback/path.ts new file mode 100644 index 0000000000000..b074412ddefb0 --- /dev/null +++ b/packages/next/shared/lib/fallback/path.ts @@ -0,0 +1,5 @@ +const path = process.browser + ? require('next/dist/compiled/path-browserify') + : require('path') + +export default path diff --git a/packages/next/shared/lib/router/utils/querystring.ts b/packages/next/shared/lib/router/utils/querystring.ts index f86d7a3c257e6..3b9fa9f2068ed 100644 --- a/packages/next/shared/lib/router/utils/querystring.ts +++ b/packages/next/shared/lib/router/utils/querystring.ts @@ -1,4 +1,4 @@ -import { ParsedUrlQuery } from 'querystring' +import type { ParsedUrlQuery } from 'querystring' export function searchParamsToUrlQuery( searchParams: URLSearchParams diff --git a/packages/next/types/misc.d.ts b/packages/next/types/misc.d.ts index 9d68b3d69d377..2a4807c84a802 100644 --- a/packages/next/types/misc.d.ts +++ b/packages/next/types/misc.d.ts @@ -340,6 +340,11 @@ declare module 'next/dist/compiled/process' { export = m } +declare module 'next/dist/compiled/path-browserify' { + import m from 'path' + export = m +} + declare module 'pnp-webpack-plugin' { import webpack from 'webpack4'