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: replace dep.module with ModuleGraph API #38

Merged
merged 3 commits into from
Oct 7, 2020

Conversation

mpreziuso
Copy link
Contributor

When running on Webpack 5.0.0-rc.4, it fails to compile and throws the following error:

 module property was removed from Dependency (use compilation.moduleGraph.getModule(dependency) instead)

This change is to use compilation.moduleGraph.getModule() to prevent that.

@fqborges
Copy link
Owner

fqborges commented Oct 7, 2020

Thanks for the work. Just a few questions before merge and publish.

Does it still works with webpack 4 after changing to ModuleGraph API?
Could it be a breaking change?

@mpreziuso
Copy link
Contributor Author

mpreziuso commented Oct 7, 2020

It's not quite OK just yet, I've been running the tests and some fail.
Will fix, push, check webpack 4 and let you know!

@mpreziuso
Copy link
Contributor Author

The changes in this PR look safe to me now: it only uses the ModuleGraph API if available and the integration tests are all green!
When upgrading to webpack 5 (and using this project as a dependency), these changes seem to work for me in my use case but integration tests don't look very happy.
I don't think this is because of these changes but rather to the fact the webpack config in the tests has a multi module entry:

entry: {
    script: ["./script.js", middlewareScript + "script"],
    style: ["./style.css", middlewareScript + "client"],
},

which doesn't seem to be supported in v5 anymore:

(node:107527) [DEP_WEBPACK_MAIN_TEMPLATE_RENDER_MANIFEST] DeprecationWarning: MainTemplate.hooks.renderManifest is deprecated (use Compilation.hooks.renderManifest instead)
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:107527) [DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST] DeprecationWarning: ChunkTemplate.hooks.renderManifest is deprecated (use Compilation.hooks.renderManifest instead)
(node:107527) [DEP_WEBPACK_MAIN_TEMPLATE_HASH_FOR_CHUNK] DeprecationWarning: MainTemplate.hooks.hashForChunk is deprecated (use JavascriptModulesPlugin.getCompilationHooks().chunkHash instead)
(node:107527) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader
(node:107527) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
	Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
	Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(node:107527) [DEP_WEBPACK_MODULE_ID] DeprecationWarning: Module.id: Use new ChunkGraph API
(node:107527) [DEP_WEBPACK_MODULE_UPDATE_HASH] DeprecationWarning: Module.updateHash: Use new ChunkGraph API
(node:107527) [DEP_WEBPACK_CHUNK_MODULES_ITERABLE] DeprecationWarning: Chunk.modulesIterable: Use new ChunkGraph API
(node:107527) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
(node:107527) [DEP_WEBPACK_CHUNK_ENTRY_MODULE] DeprecationWarning: Chunk.entryModule: Use new ChunkGraph API
(node:107527) [DEP_WEBPACK_CHUNK_GROUP_GET_MODULE_INDEX_2] DeprecationWarning: ChunkGroup.getModuleIndex2 was renamed to getModulePostOrderIndex

Error: asset style.js 129 KiB [emitted] (name: style)
asset script.js 129 KiB [emitted] (name: script)
asset style.css 47 bytes [emitted] (name: style)
Entrypoint script 129 KiB = script.js
Entrypoint style 129 KiB = style.css 47 bytes style.js 129 KiB
runtime modules 49.3 KiB 22 modules
built modules 88.3 KiB (javascript) 46 bytes (unknown) [built]
  modules by path ../../../node_modules/ 88.3 KiB
    modules by path ../../../node_modules/webpack-hot-middleware/ 22 KiB 5 modules
    modules by path ../../../node_modules/html-entities/ 57.4 KiB 4 modules
    modules by path ../../../node_modules/querystring/*.js 4.51 KiB
      ../../../node_modules/querystring/index.js 127 bytes [built] [code generated]
      ../../../node_modules/querystring/decode.js 2.34 KiB [built] [code generated]
      ../../../node_modules/querystring/encode.js 2.04 KiB [built] [code generated]
    ../../../node_modules/ansi-regex/index.js 135 bytes [built] [code generated]
    ../../../node_modules/ansi-html/index.js 4.16 KiB [built] [code generated]
  modules by path ./ 61 bytes (javascript) 46 bytes (unknown)
    ./script.js 22 bytes [built] [code generated]
    ./style.css 39 bytes [built] [code generated]
    css ../../../node_modules/css-loader/dist/cjs.js!./style.css 46 bytes [built] [code generated]

ERROR in [entry] [initial] script.js
Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)

ERROR in [entry] [initial] style.js
Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)

All tests with this config fail for the same reason - specifically:

    ✕ css-entry-with-ignored-hmr [development]
    ✕ css-entry-with-ignored-hmr [production]
    ✕ multi-page+styles [development]
    ✕ multi-page+styles [production]
    ✕ single-js+css-entry [development]
    ✕ single-js+css-entry [production]
    ✕ single-js+css-entry-mjs+css-output [development]
    ✕ single-js+css-entry-mjs+css-output [production]
    ✕ single-mjs+css-entry [development]
    ✕ single-mjs+css-entry [production]
    ✕ vendor+multi-js-entry-css-entry [production]

So we can't just upgrade to v5 yet but it's a step towards that.

@fqborges
Copy link
Owner

fqborges commented Oct 7, 2020

I was also trying to test on v5 without success. I will just publish without "official" v5 support.

@fqborges fqborges merged commit 33168dd into fqborges:master Oct 7, 2020
@fqborges
Copy link
Owner

fqborges commented Oct 7, 2020

@mpreziuso
Copy link
Contributor Author

Thanks a lot!

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