emailjs / emailjs-imap-client

Low-level JS IMAP client for all your IMAP needs.
MIT License
553 stars 122 forks source link

Native modules give me weird default export #172

Closed TomasHubelbauer closed 6 years ago

TomasHubelbauer commented 6 years ago

Hey, I am using NodeJS v9.4.0 with just emailjs-imap-client dependency and code like this:

node index.mjs --experimental-modules --harmony

import ImapClient from 'emailjs-imap-client';
import secrets from './secrets.mjs';
const client = new ImapClient('imap.fastmail.com', 993, { auth: …, useSecureTransport: true });

…gives me ImapClient is not a constructor. The reason is that the ImapClient object here is not the default export but rather an object with exports. Using this instead works:

const client = new ImapClient.default('imap.fastmail.com', 993, { auth: …, useSecureTransport: true });

I am not sure if this library needs to be adapted to support native modules or if I am doing something wrong, but I would have thought that if I do import * as ImapClient I'll get object with exports and if I do just import ImapClient I will get the default export.

Instead when I do import * as ImapClient I get object with shape { default: { LOG_…, default: fn() } } and if I do import ImapClient I get object with shape { LOG_…, default: fn() }.

Let me know if there is a way I can help debug this further.

felixhammerl commented 6 years ago

... and here's the beef with babel-transpiled versus native modules.

http://2ality.com/2015/12/babel-commonjs.html#why-isnt-the-default-export-done-like-a-commonjs-single-export

In the readme, I assumed babel, which makes this work, even though it should not. Honestly, the whole ES6 modules ecosystem is a bigger mess at this point than when promises were the new hotness.

This should work: import { default as ImapClient } from 'emailjs-imap-client'