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: library module without export statement #18176
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,9 +425,14 @@ class WebpackOptionsApply extends OptionsApply { | |
options.optimization.sideEffects === true | ||
).apply(compiler); | ||
} | ||
if (options.optimization.providedExports) { | ||
if ( | ||
options.optimization.providedExports || | ||
(options.optimization.providedExports === false && | ||
options.output.library && | ||
options.output.library.type === "module") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont' think we should rely on such things, we need to improve logic inside the plugin itself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i think this would also destroy the meaning of the config, but 'libraryType: module' does rely on the module's exportsInfo, maybe we need to simply record export by sth like 'exportsInfo' for 'output: module'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any other suggestions? I'd be glad to read the related code and fix this issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And it seems that users rarely set 'providedExport' to false because of the performance issues of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will look deeply later |
||
) { | ||
const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin"); | ||
new FlagDependencyExportsPlugin().apply(compiler); | ||
new FlagDependencyExportsPlugin(options).apply(compiler); | ||
} | ||
if (options.optimization.usedExports) { | ||
const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
const m = true | ||
|
||
export default 'issue-18056' | ||
export { React, m } | ||
|
||
it("should compile and run", () => { | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
it("should compile and run", () => { | ||
expect(issue18056.default).toBe('issue-18056'); | ||
expect(issue18056.m).toBe(true); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var webpack = require("../../../../"); | ||
|
||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = [ | ||
{ | ||
target: "node", | ||
entry: { | ||
import: "./index.js" | ||
}, | ||
optimization: { | ||
providedExports: false, | ||
usedExports: true | ||
}, | ||
output: { | ||
libraryTarget: "module", | ||
module: true, | ||
chunkFormat: "module" | ||
}, | ||
experiments: { | ||
outputModule: true | ||
}, | ||
externals: ["react"], | ||
externalsType: "module" | ||
}, | ||
{ | ||
entry: "./run.js", | ||
plugins: [ | ||
new webpack.BannerPlugin({ | ||
raw: true, | ||
banner: | ||
"import mod, { m } from './bundle0.mjs';\nlet issue18056 = { default: mod, m };" | ||
}) | ||
], | ||
output: { | ||
module: true, | ||
chunkFormat: "module" | ||
}, | ||
experiments: { | ||
outputModule: true | ||
} | ||
} | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other better way to determine whether it is an entry module during
finishModules
stage?