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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable ProvidePlugin for javascript/esm (fixes #7032) #8250

Merged
merged 3 commits into from Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/ProvidePlugin.js
Expand Up @@ -76,9 +76,8 @@ class ProvidePlugin {
normalModuleFactory.hooks.parser
.for("javascript/dynamic")
.tap("ProvidePlugin", handler);
normalModuleFactory.hooks.parser
.for("javascript/esm")
.tap("ProvidePlugin", handler);

// Disable ProvidePlugin for javascript/esm, see https://github.com/webpack/webpack/issues/7032
}
);
}
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/plugins/provide-plugin/foo.mjs
@@ -0,0 +1,3 @@
export default function foo() {
return typeof esm;
}
5 changes: 5 additions & 0 deletions test/configCases/plugins/provide-plugin/index.js
Expand Up @@ -56,3 +56,8 @@ it("should provide ES2015 modules", function() {
expect((es2015_alias)).toBe("ECMAScript Harmony");
expect((es2015_year)).toBe(2015);
});

it("should not provide for mjs", function(){
var foo = require("./foo.mjs").default;
expect(foo()).toBe("undefined");
});
3 changes: 2 additions & 1 deletion test/configCases/plugins/provide-plugin/webpack.config.js
Expand Up @@ -10,7 +10,8 @@ module.exports = {
es2015_name: ["./harmony", "default"],
es2015_alias: ["./harmony", "alias"],
es2015_year: ["./harmony", "year"],
"this.aaa": "./aaa"
"this.aaa": "./aaa",
esm: "fail"
})
]
};