From 864d401ee16ef9711c7e1165aa96f3d55a0e189b Mon Sep 17 00:00:00 2001 From: await-ovo <41503212+await-ovo@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:14:03 +0800 Subject: [PATCH] fix(next): use moduleGraph.getIssuer to avoid deprecation warning (#36329) (#36330) fix: #36329 ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` --- packages/next/server/dev/hot-reloader.ts | 14 +++++---- .../index.test.ts | 29 +++++++++++++++++++ test/lib/next-modes/next-dev.ts | 2 ++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 test/development/webpack-issuer-deprecation-warning/index.test.ts diff --git a/packages/next/server/dev/hot-reloader.ts b/packages/next/server/dev/hot-reloader.ts index 733094ec7478376..8e813c162432b82 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 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)