FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Upgrade to webpack 5 by nmintcheva · Pull Request #8 · sdinteractive/webpack-requirejs-export-plugin · GitHub

Upgrade to webpack 5 - #8

Merged
mpchadwick merged 3 commits into
sdinteractive:masterfrom
nmintcheva:webpack5-upgrade
Jun 15, 2026
Merged

Upgrade to webpack 5#8
mpchadwick merged 3 commits into
sdinteractive:masterfrom
nmintcheva:webpack5-upgrade

Conversation

nmintcheva commented Jun 11, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Goal of this PR is to fix on the magento 2.4.8-p5 upgrade

ReferenceError: module is not defined

nmintcheva changed the base branch from master to release/v3.0 June 15, 2026 14:20
nmintcheva changed the base branch from release/v3.0 to master June 15, 2026 16:52
mpchadwick requested a review from Copilot June 15, 2026 17:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR updates @sdinteractive/requirejs-export-plugin to work with webpack 5 (Magento 2.4.8-p5), addressing the runtime ReferenceError: module is not defined by changing how module exports are captured and exposed to RequireJS.

Changes:

  • Add a webpack 5 code path using compilation.hooks.processAssets + chunkGraph and runtime __webpack_require__ capture.
  • Keep a webpack 4 legacy path (still using afterOptimizeModuleIds and chunkAsset).
  • Bump package version to 4.0.0 and update the package description.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
package.json Version bump and description update to indicate webpack 5 support.
index.js Implement webpack 5-compatible export capture and asset wrapping, while retaining webpack 4 behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index.js
Comment thread index.js
Comment thread index.js
Comment thread index.js
Comment on lines +146 to 150
compilation.hooks.chunkAsset.tap('RequireJsExportPlugin', (chunk, filename) => {
const modules = chunk.modulesIterable ? Array.from(chunk.modulesIterable) : [];
const needsImport = gatherRequireJsImports(modules);
const needsExport = gatherRequireJsExports(modules);

nmintcheva requested a review from Copilot June 15, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

Comment thread index.js
Comment on lines +140 to +142
if (shouldExport(module) && module._source) {
const definition = '__webpack_exports__[' + JSON.stringify(module.id) + '] = module.exports;';
module._source = new ConcatSource(module._source, '\n', definition);
Comment thread index.js
Comment on lines +74 to +77
window.define(${jsonName}, ${jsonDefineStubs}, function () {
var exp = __requirejs_exports__[${jsonId}];
return (exp && exp.__esModule && exp.default) ? exp.default : exp;
});`;
Comment thread index.js
)
.join('\n');

const prolog = generateProlog(chunk.id, needsImport, needsExport);
Comment thread index.js
Comment on lines +95 to +96
compiler.options.output = compiler.options.output || {};
compiler.options.output.iife = false;
Comment thread index.js
Comment on lines +126 to +131
for (const filename of chunk.files) {
compilation.updateAsset(
filename,
(old) => new ConcatSource(prolog, '\n', old, '\n', captureCode, '\n', epilog)
);
}
Comment thread index.js
Comment on lines +117 to +121
const captureCode = needsExport
.map(({ id }) =>
` try { __requirejs_exports__[${JSON.stringify(id)}] = __webpack_require__(${JSON.stringify(id)}); } catch(e) {}`
)
.join('\n');
mpchadwick merged commit 5f4fef1 into sdinteractive:master Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL