You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mixed default and named exports changes default export #712
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
I am pretty sure you will ask why we do need default exports, in my case I've a library that is used by a lot of people, I switched to microbundle a bit ago and realized later on this was buggy and it won't work with SSR unless we do module.exports, thing is even if I want to change the way we import / export to work with microbundle, I need to provide backwards compatibility or something...
I think this might be related to #264 and #306 but I am not completely sure if that's the case.
Reacted by Dani Akash, Aleksandr Smyshliaev, Evan Purkhiser, Tord Johan Espe, Michael Rodov and manjunath-teachmint
FWIW TypeScript has a setting that fixes this ("commonjsInterop" or something to that effect), however that's the crux of the issue: TypeScript doesn't have a logical behaviour for modules that are situationally CommonJS or ESM. The only generalized solution is to explicitly define the root export.
Activity
developit commentedon Aug 31, 2020
Hiya. This is done intentionally. Here's what you can do to produce CommonJS and UMD bundles that don't have the issue:
{ "scripts": { "build": "microbundle -f cjs,umd src/index.cjs.js && microbundle -f es,modern src/index.js" } }Now
require('your-lib')===GoogleMap, butrequire('your-lib').namedExport1===namedExport1.I might add an option to do this automatically.
itsmichaeldiego commentedon Sep 1, 2020
Works like a charm, thanks for the quick response!
Would be awesome if you add an option to do this automatically! 🎉
Feel free to close the issue, unless you want to keep it for that option you want to add.
wardpeet commentedon Sep 2, 2020
@developit any implications why we don't do this behaviour by default if it's umd/cjs? Any reasons that make this a big nono?
developit commentedon Sep 2, 2020
TBH I don't think there would be any negative effects, it just hasn't been implemented.
quantizor commentedon Sep 6, 2020
@developit would love this
developit commentedon Nov 5, 2020
same lol
quantizor commentedon Nov 5, 2020
I've been getting a lot of bug reports on how this works in markdown-to-jsx: quantizor/markdown-to-jsx#333
https://github.com/probablyup/markdown-to-jsx/blob/676e53ff33036fd0527a9ea79cd478a74ea20513/index.cjs.tsx#L1-L3
Webpack doesn't seem to be able to resolve this
paulsmithkc commentedon Dec 15, 2020
Couldn't you do this for both? Rather than having two different files?
evanpurkhiser commentedon Jan 6, 2021
Unfortunately this work around breaks typescript's understanding of the exports
asmyshlyaev177 commentedon Jan 6, 2021
Can use JSDoc for it.
make-github-pseudonymous-again commentedon Mar 18, 2021
Can't this shadow/replace
namedExportXproperties ofGoogleMapif they exist?🩹 fix: Make all tests pass again.
📚 docs: Fix import instructions.
make-github-pseudonymous-again commentedon Mar 18, 2021
Would the following work?
or
or
Should work as long as
defaultis not a name you care about?!EDIT: OK. This does not work since default is not a valid identifier.
wardpeet commentedon Mar 26, 2021
is not a allowed as default is a reserved keyword https://mathiasbynens.be/notes/reserved-keywords
qwelias commentedon May 19, 2021
It breaks type acquisition in our case :(
olesku/eventhub-jsclient#9
developit commentedon Jun 3, 2021
@qwelias you should be able to use an intermediary type definition to fix this:
FWIW TypeScript has a setting that fixes this ("commonjsInterop" or something to that effect), however that's the crux of the issue: TypeScript doesn't have a logical behaviour for modules that are situationally CommonJS or ESM. The only generalized solution is to explicitly define the root export.
DavidWells commentedon Aug 5, 2021
Glad I found this! #712 (comment)
I set up a demo repo if anyone is curious to see this in action https://github.com/DavidWells/microbundle-cjs-default-export-fix/