-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
umd-compliance of babel-plugin-transform-modules-umd #10696
Comments
Hey @fuweichin! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
There are three changes on the proposed expected code.
Actually it is not compliant to CommonJS spec which only defined
Since we have defined the exports of the module, I don't think we still need to return a value.
By doing so the global object would not provide access to other exported properties. For example export default React;
export { Component }; Now if the user uses |
Ask in reply:
Possible solution: How about adding an property in babel config to specify which umd template the plugin is going to use? then let the plugin prepare several templates for users to choose from? like this module.exports={
"plugins": [
["@babel/plugin-transform-modules-umd", {
"umdTemplate": "amdWebGlobal",// or "commonjsStrictGlobal", "returnExportsGlobal", ...
}]
]
} |
@fuweichin The thing with |
@nicolo-ribaudo |
Will a fix be provided for this soon? I am currently using a library (FileSaver.js) where the UMD transform is not working properly (per this issue: eligrey/FileSaver.js#646. I think the issue in FileSaver.js is simply a matter of an invalid UMD wrapper. If the babel UMD transform want's to modify an 'exports', the AMD spec supports this by using the patern:
Otherwise, you need to return the value you are assigning to exports as the exported module (in AMD). |
The other solution is to just return the module value. I think setting |
I'd like to voice support for this insofar as it would enable resolving this issue: eligrey/FileSaver.js#538 as discussed in this PR: eligrey/FileSaver.js#602 |
I think I was hit by this limitation whe trying to update babel to version 7 in autosize module for debian. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990458 for details and finally I had to use rollup to generate the umd bundle. |
any update ? |
Bug Report
Current Behavior
With
babel-plugin-transform-modules-umd
(npm@babel/plugin-transform-modules-umd version@7.7.0
), there are lots of limitations to transform mjs to js:export default xxx
return xxx
module.exports=xxx
Input Code
foo.mjs
Output Code
foo.js
Expected behavior/code
Note with such behavior, you shouldn't use
export {xxx}
andexport default xxx
both at once, since ES6 module has features which AMD module and CommonJS module don't support.Babel Configuration (.babelrc, package.json, cli command)
Environment
cli
Possible Solution
Now that the plugin targets umd, why not see umdjs - returnExports for some umd considerations?
Additional context/Screenshots
Is my babel configuration mistaken, or I have used a wrong plugin?
I have once forked and published babel-plugin-transform-modules-simple-amd for babel 7.x, or maybe I need fork and publish another plugin, e.g.
babel-plugin-transform-modules-simple-umd
, to do that kind of job?The text was updated successfully, but these errors were encountered: