Add an ES module entrypoint
rubys opened this issue · 5 comments
Trying import syntax with node 13 results in:
import {Mutex} from 'async-mutex';
^^^^^
SyntaxError: The requested module 'async-mutex' does not provide an export named 'Mutex'
The following, however, works:
import AsyncMutex from 'async-mutex';
const mutex = new AsyncMutex.Mutex();
That's not a bug; you are trying to do a ES import from a commonjs module (async-mutex), and node does not support named exports in that constellation (check https://nodejs.org/api/esm.html#esm_import_statements).
However, I'll investigate providing an ES entrypoint into the package.
At a minimum, it is a documentation issue as the instructions for an ES6 import don't work natively with node.js:
https://github.com/DirtyHairy/async-mutex#importing
The issue is that you are only providing a default export. Adding an additional export would likely address this:
export { Mutex };
The issue is that you are only providing a default export. Adding an additional export would likely address this:
You are wrong: https://github.com/DirtyHairy/async-mutex/blob/master/src/index.ts
The export is there, and it works fine with any other module bundler out there --- I am using the library myself extensively. ES module support in NodeJS is clearly marked as experimental and may still change. If you use it, you should be careful and aware of its limitations. As I said, I will look into adding an ES entrypoint.
I've added a note to the documentation.
I just released 0.2.1. This version now supports the native ES6 loader starting with node 12 (earlier versions will not work).