From 7a23b7809f15fb45f95c4b4bb36d9d167b9237ca Mon Sep 17 00:00:00 2001 From: slorber Date: Tue, 30 Mar 2021 17:18:19 +0200 Subject: [PATCH] Fix webpack 5 deprecation warning: (node:38087) [DEP_WEBPACK_CHUNK_GET_MODULES] DeprecationWarning: Chunk.getModules: Use new ChunkGraph API --- source/ReactLoadableSSRAddon.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/ReactLoadableSSRAddon.js b/source/ReactLoadableSSRAddon.js index bd63819..a416720 100644 --- a/source/ReactLoadableSSRAddon.js +++ b/source/ReactLoadableSSRAddon.js @@ -183,9 +183,10 @@ class ReactLoadableSSRAddon { * It tries to mimic https://github.com/webpack/webpack/blob/webpack-4/lib/Stats.js#L632 * implementation without expensive operations * @param {array} compilationChunks + * @param {array} chunkGraph * @returns {array} */ - getMinimalStatsChunks(compilationChunks) { + getMinimalStatsChunks(compilationChunks, chunkGraph) { const compareId = (a, b) => { if (typeof a !== typeof b) { return typeof a < typeof b ? -1 : 1; @@ -218,8 +219,9 @@ class ReactLoadableSSRAddon { files: this.ensureArray(chunk.files).slice(), hash: chunk.renderedHash, siblings: Array.from(siblings).sort(compareId), - // TODO: This is the final deprecation warning needing to be solved. - modules: chunk.getModules(), + // Webpack5 emit deprecation warning for chunk.getModules() + // "DEP_WEBPACK_CHUNK_GET_MODULES" + modules: WEBPACK_5 ? chunkGraph.getChunkModules(chunk) : chunk.getModules(), }); }); @@ -247,7 +249,7 @@ class ReactLoadableSSRAddon { || ''; this.getEntrypoints(this.stats.entrypoints); - this.getAssets(this.getMinimalStatsChunks(compilation.chunks)); + this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph)); this.processAssets(compilation.assets); this.writeAssetsFile();