3 ms·
Sorry about nitpicking, but I feel that we shouldn't say that CJS has named exports. It does not. CJS has a single export which might be an object. And objects
by indeyets 6y ago
Sorry about nitpicking, but I feel that we shouldn't say that CJS has named exports. It does not.
CJS has a single export which might be an object. And objects have named properties/fields.
On the other hand, ESM CAN have unnamed "default" export and CAN have arbitrary number of named exports.
- DaiPlusPlus 6y ago> On the other hand, ESM CAN have unnamed "default" export and CAN have arbitrary number of named exports. And this is a constant source of confusion and frustration for me when working with so many npm modules lately...
- jkrems 6y ago> On the other hand, ESM CAN have unnamed "default" export and CAN have arbitrary number of named exports. To nitpick on the nitpick: ESM only has named exports. It just treats the export named "default" differently in some scenarios and has special syntax for it. So, roughly: * CJS: Exports a single value which may or may not be an object. When assigning the exported value to local variables, destructuring can be used to access individual exports properties. * ESM: Exports a namespace of named bindings. When importing the bindings to local aliases, the name of the alias can be changed using `as`. There's special syntax for importing the binding with the name "default". It's somewhat unfortunate that the syntax _looks_ so close without being all that close.