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

Uncaught ReferenceError: module is not defined When directly used in Browser. #80

Open
MinimalistYing opened this issue Jun 17, 2019 · 2 comments

Comments

@MinimalistYing
Copy link

I have an library use babel 7 and @babel/plugin-transform-modules-umd to transform ES6 Modules into UMD.
And now i want to use this library to remove the ugly use of default.
I use babel-plugin-add-module-exports v1.0.2 in my project.
But the output code ended with

// ......
  var _default = new Message();

  _exports.default = _default;
  module.exports = exports.default;

When the output code running in browser, this Error comes out

Uncaught ReferenceError: module is not defined

I found a closed issue don't handle an amd module #57 here.
It seems i have the same issue in version 1.0.2

How can i solve this problem ? Thanks.

@zhixinpeng
Copy link

I have the same problem with you

@DvdGiessen
Copy link
Contributor

Just ran into this as well. After looking into it for a bit I decided to drop my dependency on this plugin and implement a separate solution; this plugin isn't really suited or aimed at use in combination with UMD or the browser.

I wrote my own Babel transform which works together with the UMD transform plugin to achieve the same effect as this plugin does with the addDefaultProperty setting enabled. See my babel.config.js file. Note it contains one additional feature specific for my use case on line 50, namely adding a secondary titlecased export when loaded in the browser. You may want to remove that second assignment.

While this solution is rather specialized, perhaps it might prove useful for others with similar use cases.

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

No branches or pull requests

3 participants