-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
For an ESM project, importing the webpack plugin causes an "SyntaxError" error #2368
Comments
I believe this is because it emits commonjs only as it is just tsc |
Here's additional info: https://publint.dev/@module-federation/[email protected]
|
like this? #2376 |
@patricklafrance try |
No luck, still not working. I still get:
Maybe this online linter is not as good as it seems 😆 Is there a specific reason why you are not releasing ESM packages? |
I logged this issue more as a FYI, I didn't really mind because there seemed to be an easy workaround by using: import ModuleFederation from "@module-federation/enhanced/webpack"; Instead of: import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack"; But now, I am really stuck. Turns out that the webpack CLI requires: import ModuleFederation from "@module-federation/enhanced/webpack"; But the Jest CLI requires: import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack"; So now I am stuck, not sure what to do about this! I updated my reproduction to include a reproduction with Jest. Hope this help! |
I stumbled on this article which explains how a CommonJs module should be exported to be consumable in ESM as a named import. Following the content of the article, I manually updated "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModuleFederationPlugin = void 0;
var ModuleFederationPlugin_1 = require("./wrapper/ModuleFederationPlugin");
Object.defineProperty(exports, "ModuleFederationPlugin", { enumerable: true, get: function () { return __importDefault(ModuleFederationPlugin_1).default; } });
//# sourceMappingURL=webpack.js.map to: var ModuleFederationPlugin_1 = require("./wrapper/ModuleFederationPlugin");
exports.ModuleFederationPlugin = ModuleFederationPlugin_1.default; And now I can use a named import from my webpack config file: import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack"; To be honest, the original code seems alright, I am not sure why it's not working. |
The issue is with this line: Object.defineProperty(exports, "ModuleFederationPlugin", { enumerable: true, get: function () { return __importDefault(ModuleFederationPlugin_1).default; } }); When replaced by either: exports.ModuleFederationPlugin = __importDefault(ModuleFederationPlugin_1).default; or: Object.defineProperty(exports, "ModuleFederationPlugin", { enumerable: true, value: __importDefault(ModuleFederationPlugin_1).default }); It works as expected. |
I also added 3 CI builds to my reproduction repository showing that it's not working with either Node 20, 21 and 22: |
Closing as it's been fixed in https://github.com/module-federation/core/releases/tag/v0.1.11 🙏🏻 |
Describe the bug
For an ESM project, importing the webpack plugin as shown in the documentation:
Causes the following error:
If I instead replace the import for:
And instanciate the plugin with the following:
Now everything works fine.
I am not sure if this is an issue with the documentation or how the code is packaged?
Thank you,
Patrick
Reproduction
https://github.com/patricklafrance/mf-enhanced-import-webpack-plugin-issue
Used Package Manager
pnpm
System Info
Validations
The text was updated successfully, but these errors were encountered: