diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 647194bfbef86..2c62c2d34243c 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -959,11 +959,6 @@ export default async function getBaseWebpackConfig( }, } - const nonUserCondition = { - include: /node_modules/, - exclude: babelIncludeRegexes, - } - let webpackConfig: webpack.Configuration = { parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined, externals: targetWeb @@ -1256,13 +1251,6 @@ export default async function getBaseWebpackConfig( }, ], }, - { - ...nonUserCondition, - // Make all non-user modules to be compiled in a single layer - // This avoids compiling them mutliple times and avoids module id changes - issuerLayer: 'middleware', - layer: '', - }, ...(!config.images.disableStaticImages ? [ { diff --git a/test/integration/middleware/hmr/node_modules/shared-package/index.js b/test/integration/middleware/hmr/node_modules/shared-package/index.js new file mode 100644 index 0000000000000..a8653a9c9264c --- /dev/null +++ b/test/integration/middleware/hmr/node_modules/shared-package/index.js @@ -0,0 +1 @@ +module.exports = 42 diff --git a/test/integration/middleware/hmr/node_modules/shared-package/package.json b/test/integration/middleware/hmr/node_modules/shared-package/package.json new file mode 100644 index 0000000000000..1587a669681c9 --- /dev/null +++ b/test/integration/middleware/hmr/node_modules/shared-package/package.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} diff --git a/test/integration/middleware/hmr/pages/about/_middleware.js b/test/integration/middleware/hmr/pages/about/_middleware.js index 66902bd191d7f..3146e1d20277e 100644 --- a/test/integration/middleware/hmr/pages/about/_middleware.js +++ b/test/integration/middleware/hmr/pages/about/_middleware.js @@ -1,5 +1,7 @@ import { NextResponse } from 'next/server' +import magicValue from 'shared-package' export function middleware(request) { + if (magicValue !== 42) throw new Error('shared-package problem') return NextResponse.rewrite(new URL('/about/a', request.url)) } diff --git a/test/integration/middleware/hmr/pages/index.js b/test/integration/middleware/hmr/pages/index.js index 36f47d6337750..fa99cf9c2eb8b 100644 --- a/test/integration/middleware/hmr/pages/index.js +++ b/test/integration/middleware/hmr/pages/index.js @@ -1,3 +1,6 @@ +import magicValue from 'shared-package' +if (magicValue !== 42) throw new Error('shared-package problem') + export default function Home() { return (