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

when setting optimization.providedExports to false, outputModule wouldn't generate export statement #18056

Open
alexander-akait opened this issue Feb 5, 2024 Discussed in #17902 · 3 comments · May be fixed by #18176
Open

Comments

@alexander-akait
Copy link
Member

Discussed in #17902

Originally posted by hardfist December 28, 2023
I'm not sure whether it's by design or bug, it seems outputModule relys on setting optimization.providedExports to true, otherwise it wouldn't generate the export statement
you can reproduce here https://github.com/web-infra-dev/rspack-repro/tree/esm-output

  • optimization.providedExports=true
const external_react_namespaceObject = x({ ["default"]: () => __WEBPACK_EXTERNAL_MODULE_react__["default"] });
;// CONCATENATED MODULE: ./src/index.js

console.log({React: external_react_namespaceObject["default"]});

var __webpack_exports__React = __webpack_exports__._;
export { __webpack_exports__React as React };
  • optimization.providedExports = false
var __webpack_exports__ = {};

;// CONCATENATED MODULE: external "react"
var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
var y = x => () => x
const external_react_namespaceObject = x({ ["default"]: () => __WEBPACK_EXTERNAL_MODULE_react__["default"] });
;// CONCATENATED MODULE: ./src/index.js

console.log({React: external_react_namespaceObject["default"]});
// missing the export statement


```</div>
@alexander-akait
Copy link
Member Author

@hardfist Feel free to send a PR

@hai-x
Copy link
Contributor

hai-x commented Mar 9, 2024

I found that the issue has always existed since version 5.41.0 which add EcmaScript modules support.

I'm willing to fix this issue, and I've spent some time looking at it.

The problem I found is that when renderStartup in ModuleLibraryPlugin moduleGraph.getExportsInfo(module).exports equals to [] which caused by optimization.providedExports: false.

const exportsInfo = moduleGraph.getExportsInfo(module);

I have a solution that when library === module and providedExport === false we also flag exportsInfo by FlagDependencyExportsPlugin but only for the entry module. Not sure if this is the optimal solution, but I tested it and it is indeed feasible.

But I also feel that doing so violates the meaning of providedExport. I will send PR to fix this issue.

@alexander-akait
Copy link
Member Author

@hai-x yeah, feel free to send a pr

@hai-x hai-x linked a pull request Mar 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Priority - High
Development

Successfully merging a pull request may close this issue.

3 participants