question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SES module emulation of CommonJS named exports

See original GitHub issue

Considering 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:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
kriskowalcommented, May 25, 2021

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. 😉

1reaction
erightscommented, May 25, 2021

What does the square bracket notation above mean?

Such as [Object: null prototype] [Module] vs [Module: null prototype]

?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found