From c25bcade0c05a4cddd1f266b73acdb76e6ded4e7 Mon Sep 17 00:00:00 2001 From: await-ovo <13152410380@163.com> Date: Thu, 21 Apr 2022 13:16:50 +0800 Subject: [PATCH 1/2] fix(next): use moduleGraph.getIssuer to avoid deprecation warning (#36329) --- packages/next/server/dev/hot-reloader.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/next/server/dev/hot-reloader.ts b/packages/next/server/dev/hot-reloader.ts index 74e93f2745db3e5..b04903004d1e995 100644 --- a/packages/next/server/dev/hot-reloader.ts +++ b/packages/next/server/dev/hot-reloader.ts @@ -106,12 +106,16 @@ const matchNextPageBundleRequest = route( ) // Recursively look up the issuer till it ends up at the root -function findEntryModule(issuer: any): any { - if (issuer.issuer) { - return findEntryModule(issuer.issuer) +function findEntryModule( + compilation: webpack5.Compilation, + issuerModule: any +): any { + const issuer = compilation.moduleGraph.getIssuer(issuerModule) + if (issuer) { + return findEntryModule(compilation, issuer) } - return issuer + return issuerModule } function erroredPages(compilation: webpack5.Compilation) { @@ -121,7 +125,7 @@ function erroredPages(compilation: webpack5.Compilation) { continue } - const entryModule = findEntryModule(error.module) + const entryModule = findEntryModule(compilation, error.module) const { name } = entryModule if (!name) { continue From af51d871dd5acf26ad54aa4b1faf3ce7d6de1686 Mon Sep 17 00:00:00 2001 From: await-ovo <13152410380@163.com> Date: Thu, 21 Apr 2022 20:16:08 +0800 Subject: [PATCH 2/2] chore: add test cases for webpack module issuer deprecation warning --- .../index.test.ts | 29 +++++++++++++++++++ test/lib/next-modes/next-dev.ts | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 test/development/webpack-issuer-deprecation-warning/index.test.ts diff --git a/test/development/webpack-issuer-deprecation-warning/index.test.ts b/test/development/webpack-issuer-deprecation-warning/index.test.ts new file mode 100644 index 000000000000000..4951405b8f83d31 --- /dev/null +++ b/test/development/webpack-issuer-deprecation-warning/index.test.ts @@ -0,0 +1,29 @@ +import { createNext } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { renderViaHTTP } from 'next-test-utils' + +describe('webpack-issuer-deprecation-warning', () => { + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: { + 'pages/index.js': ` + export default function Page() { + return

hello world + } + `, + }, + dependencies: {}, + }) + }) + afterAll(() => next.destroy()) + + it('should not appear deprecation warning about webpack module issuer', async () => { + const html = await renderViaHTTP(next.url, '/') + expect(html).toContain('Syntax Error') + expect(next.cliOutput).not.toContain( + '[DEP_WEBPACK_MODULE_ISSUER] DeprecationWarning: Module.issuer: Use new ModuleGraph API' + ) + }) +}) diff --git a/test/lib/next-modes/next-dev.ts b/test/lib/next-modes/next-dev.ts index 0a27917038f9fbe..ad736fb099c850c 100644 --- a/test/lib/next-modes/next-dev.ts +++ b/test/lib/next-modes/next-dev.ts @@ -40,6 +40,8 @@ export class NextDevInstance extends NextInstance { }, }) + this._cliOutput = '' + this.childProcess.stdout.on('data', (chunk) => { const msg = chunk.toString() process.stdout.write(chunk)