callback-to-async-iterator icon indicating copy to clipboard operation
callback-to-async-iterator copied to clipboard

[SUGGESTION] Use a standard CommonJS export

Open WaldoJeffers opened this issue 6 years ago • 1 comments

Currently, callback-to-async-iterator is written using ES6 modules, and transpiled to CommonJS using babel-plugin-transform-modules-commonjs.

The export in the result file in the dist folder looks like this:

exports.default = callbackToAsyncIterator;

which means in a standard CommonJS environment, you have to write something like this to use it:

const callbackToAsyncIterator = require('callback-to-async-iterator').default

This is a bit unexpected, because I think this module is primarily targeted at NodeJS environments, and the docs don't mention it.

I would suggest using regular CommonJS exports in the source code, to make sure the exported dist/index.js file looks like this:

module.exports = callbackToAsyncIterator

This will probably not make any differences for people using it in a ES6 module environment, because tools like Babel or Webpack usually interop quite nicely with CommonJS modules.

What are your thoughts on this? I can work on a PR if that sounds good

WaldoJeffers avatar Aug 11 '19 09:08 WaldoJeffers

I'm importing this as an ES6 module natively in Node 17 yet I still seem to have to use the "default" named export…

import asyncify from 'callback-to-async-iterator'

asyncify(cb)
TypeError: asyncify is not a function 
// have to use asyncify.default 

laggingreflex avatar Dec 30 '21 01:12 laggingreflex