-
Notifications
You must be signed in to change notification settings - Fork 11
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
Named exports as default export #26
Comments
The exports are the same as the default I'm assuming everyone developed their libraries based on I'm curious to know cases when people have used the default import, since both Please let me know |
This doesn’t throw warning: const url = require('url'); This does throw warning: import url from `url`;
Documentation is misleading in saying this:
|
This happens because the module is being imported as ESM. @janicklas-ralph - It might be worth removing the |
@developit maybe export object (with all named exports as properties of that object) as default export and rely on tree-shaking from bundlers for any unwanted exports? |
native-url
exposes methods thorugh named exports. To get default Nodeurl
behavior you would need to import entire module contentsThis is fine for your own code, but dependencies will throw error since they can’t find default export by default, and most 3rd party code using Node
url
depend on that default export to be available.To fix this, it’s best to make changes to code at compile time to expose every named export as property of object which should be default export.
Here is a Babel plugin code which achieves that:
And here is how you apply it with Webpack:
After that you can use both modules’ named exports as default export.
Is this something which should be documented for both Webpack and Rollup, or should
native-url
expose default export by default?The text was updated successfully, but these errors were encountered: