SES module emulation of CommonJS named exports
See original GitHub issueConsidering the following case:
// exports.cjs
exports.name = 1;
// module-exports.cjs
module.default = 1;
// imports.mjs (or imports.js for node -r esm imports.js)
import exportsName from './exports.cjs';
import * as exportsNameStar from './exports.cjs';
import moduleExports from './module-exports.cjs';
import * as moduleExportsStar from './module-exports.cjs';
console.log({
exportsName,
exportsNameStar,
moduleExports,
moduleExportsStar,
});
Node.js 12:
(node:10205) ExperimentalWarning: The ESM module loader is experimental.
{
exportsName: { name: 1 },
exportsNameStar: [Module] { default: { name: 1 } },
moduleExports: 1,
moduleExportsStar: [Module] { default: 1 }
}
Node.js 14:
{
exportsName: { name: 1 },
exportsNameStar: [Module] { default: { name: 1 }, name: 1 },
moduleExports: 1,
moduleExportsStar: [Module] { default: 1 }
}
Node.js 16:
{
exportsName: { name: 1 },
exportsNameStar: [Module: null prototype] { default: { name: 1 }, name: 1 },
moduleExports: 1,
moduleExportsStar: [Module: null prototype] { default: 1 }
}
Node.js 16 node -r esm
{
exportsName: { name: 1 },
exportsNameStar: [Object: null prototype] [Module] { default: { name: 1 }, name: 1 },
moduleExports: 1,
moduleExportsStar: [Object: null prototype] [Module] { default: 1 }
}
SES does not yet implement all of these cases and should provide some consistent story, perhaps even a migration path from Node.js 14 to 16 semantics on a per-package basis.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Proposal: Allow CommonJS modules to declare ESM named ...
This shows how to produce correct ESM exports using output of ESM code translated by babel. This does not address API compatibility so...
Read more >How to write CommonJS exports that can be name-imported ...
This blog post explores how to write CommonJS modules so that their exports can be name-imported from ESM modules on Node.js.
Read more >Sending email using Amazon SES - AWS SDK for JavaScript
In this example, use a Node.js module to send email with Amazon SES. Create a libs directory, and create a Node.js module with...
Read more >Node Module Exports Explained - freeCodeCamp
There's another way of exporting from a Node.js module called "named export". Instead of assigning the whole module.exports to a value, ...
Read more >JavaScript - Parcel
ES modules. #. ES module syntax is the standard way to import and export values between files in JavaScript. It should be preferred...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The output above is verbatim from the Node.js console and I don’t know how to interpret that.
⚠️ Don’t get drawn into the nerd-snipe. I posted the issue so I could clear it out of my working copy and not think about it for a long time. 😉
What does the square bracket notation above mean?
Such as
[Object: null prototype] [Module]vs[Module: null prototype]?