diff --git a/packages/next/src/build/create-compiler-aliases.ts b/packages/next/src/build/create-compiler-aliases.ts index e6ed5c13e89e1..afd8d3e16c624 100644 --- a/packages/next/src/build/create-compiler-aliases.ts +++ b/packages/next/src/build/create-compiler-aliases.ts @@ -35,7 +35,6 @@ export function createWebpackAliases({ appDir, dir, reactProductionProfiling, - hasRewrites, }: { distDir: string isClient: boolean @@ -46,12 +45,8 @@ export function createWebpackAliases({ appDir: string | undefined dir: string reactProductionProfiling: boolean - hasRewrites: boolean }): CompilerAliases { const pageExtensions = config.pageExtensions - const clientResolveRewrites = require.resolve( - '../shared/lib/router/utils/resolve-rewrites' - ) const customAppAliases: CompilerAliases = {} const customDocumentAliases: CompilerAliases = {} @@ -170,15 +165,6 @@ export function createWebpackAliases({ [RSC_DYNAMIC_IMPORT_WRAPPER_ALIAS]: 'next/dist/build/webpack/loaders/next-flight-loader/track-dynamic-import', - ...(isClient || isEdgeServer - ? { - [clientResolveRewrites]: hasRewrites - ? clientResolveRewrites - : // With webpack 5 an alias can be pointed to false to noop - false, - } - : {}), - '@swc/helpers/_': path.join( path.dirname(require.resolve('@swc/helpers/package.json')), '_' diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 1541165b5ee37..6c2d47c5d0fb0 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -777,7 +777,6 @@ export default async function getBaseWebpackConfig( appDir, dir, reactProductionProfiling, - hasRewrites, }), ...(isClient ? { diff --git a/packages/next/src/shared/lib/router/router.ts b/packages/next/src/shared/lib/router/router.ts index 807d91c79fb50..f799067b70917 100644 --- a/packages/next/src/shared/lib/router/router.ts +++ b/packages/next/src/shared/lib/router/router.ts @@ -22,7 +22,6 @@ import mitt from '../mitt' import { getLocationOrigin, getURL, loadGetInitialProps, ST } from '../utils' import { isDynamicRoute } from './utils/is-dynamic' import { parseRelativeUrl } from './utils/parse-relative-url' -import resolveRewrites from './utils/resolve-rewrites' import { getRouteMatcher } from './utils/route-matcher' import { getRouteRegex } from './utils/route-regex' import { formatWithValidation } from './utils/format-url' @@ -46,6 +45,13 @@ import { handleSmoothScroll } from './utils/handle-smooth-scroll' import type { Params } from '../../../server/request/params' import { MATCHED_PATH_HEADER } from '../../../lib/constants' +let resolveRewrites: typeof import('./utils/resolve-rewrites').default +if (process.env.__NEXT_HAS_REWRITES) { + resolveRewrites = ( + require('./utils/resolve-rewrites') as typeof import('./utils/resolve-rewrites') + ).default +} + declare global { interface Window { /* prod */