Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix chunk.getModules() webpack 5 deprecation warning #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

slorber
Copy link
Contributor

@slorber slorber commented Mar 30, 2021

Summary

Follow-up of the work of @RDIL for Docusaurus 2 to support Webpack 5 (facebook/docusaurus#4089)

We have a Webpack 5 deprecation warning: chunk.getModules() is deprecated and should be replaced by the chunkGraph API.

(node:38087) [DEP_WEBPACK_CHUNK_GET_MODULES] DeprecationWarning: Chunk.getModules: Use new ChunkGraph API
    at Function.getChunkGraphForChunk (/Users/sebastienlorber/Desktop/projects/docusaurus/node_modules/webpack/lib/ChunkGraph.js:1542:10)
    at Chunk.getModules (/Users/sebastienlorber/Desktop/projects/docusaurus/node_modules/webpack/lib/Chunk.js:217:21)
    at /Users/sebastienlorber/Desktop/projects/docusaurus/node_modules/react-loadable-ssr-addon-webpack-5/lib/ReactLoadableSSRAddon.js:154:26
    at Array.forEach (<anonymous>)
    at /Users/sebastienlorber/Desktop/projects/docusaurus/node_modules/react-loadable-ssr-addon-webpack-5/lib/ReactLoadableSSRAddon.js:147:17
    at Array.reduce (<anonymous>)

To help review, wasn't able to find doc about the new ChunkGraph API, but it seems it is equivalent, as getModules() use this new API now and just add a deprecation warning

	getModules() {
		return ChunkGraph.getChunkGraphForChunk(
			this,
			"Chunk.getModules",
			"DEP_WEBPACK_CHUNK_GET_MODULES"
		).getChunkModules(this);
	}

Why

Support Webpack 5 without warnings

Checklist

  • Your code builds clean without any errors or warnings
  • You are using approved terminology
  • You have added unit tests, if apply.

Emojis for categorizing pull requests:

🐛 Bug fix (:bug:)

(node:38087) [DEP_WEBPACK_CHUNK_GET_MODULES] DeprecationWarning: Chunk.getModules: Use new ChunkGraph API
@slorber
Copy link
Contributor Author

slorber commented Mar 30, 2021

On the Docusaurus PR (facebook/docusaurus#4089), we'll be using my local fork react-loadable-ssr-addon-v5-slorber until this PR is merged / published.

Deploy preview at https://deploy-preview-4089--docusaurus-2.netlify.app/

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case this isn't present for webpack 4

Suggested change
this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph));
this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph || null));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think chunkGraph is present in webpack4, but not sure to understand why this call is needed? Do we want null instead of undefined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Just trying to avoid strict mode madness where possible, but this might not be entirely needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants