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 libraryTarget is set to module, the externals configuration appends hardcoded arrow functions that cannot be transformed #17861

Closed
versole opened this issue Dec 12, 2023 · 3 comments · Fixed by #17919

Comments

@versole
Copy link
Contributor

versole commented Dec 12, 2023

webpack version :5.89.0

libraryTarget: module
fileName: bundle.js
externals: react, react-dom

babel settings:@babel/preset-env @babel/preset-react

bundle.js file still includes arrow function like
external_react_dom_x = y => { var x = {}; __webpack_require__.d(x, y); return x; } var external_react_dom_y = x => () => x // from getSourceForModuleExternal or generateModuleRemapping
image

I need to provide a component to another project, but that project uses tools like 'es-check' which do not allow arrow functions.

Is there any method that could help me transform these hardcoded arrow functions into normal functions?

@alexander-akait
Copy link
Member

alexander-akait commented Dec 26, 2023

We can fix it, but if your browser supports modules, it means you have support of arrow functions

@versole
Copy link
Contributor Author

versole commented Dec 26, 2023

We can fix it, but if your browser supports modules, it means you have support of arrow functions

How are you going to fix it?If the issue is converting arrow functions to regular functions, I’m willing to create a PR to resolve it.

@alexander-akait
Copy link
Member

@versole We have https://github.com/webpack/webpack/blob/main/lib/RuntimeTemplate.js#L139 and should use there to generate code, so if you will set output.environment.arrowFunction to false and we will generate a regular function, so the fix is easy, you can send a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants