emailjs / emailjs-imap-client

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

Not compatible with NodeJS!? #182

Closed jhoermann closed 6 years ago

jhoermann commented 6 years ago

I get this error on startup: `import ImapClient from 'emailjs-imap-client'; ^^^^^^

SyntaxError: Unexpected token import
    at new Script (vm.js:51:7)
    at createScript (vm.js:136:10)
    at Object.runInThisContext (vm.js:197:10)
    at Module._compile (module.js:613:28)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    ...

`

With Node Version: node -v v9.10.1

As stated here: https://nodejs.org/api/esm.html#esm_unsupported NodeJS is not (yet) compatible with 'import'. My questions:

  1. What is the last compatible Version of this module?
  2. Why is the version 3.0.7 on npm when its not compatible with node?

Greetings, Jochen

felixhammerl commented 6 years ago

You can't just use ES6 modules without transpiling. The lib is transpiled to commonjs modules. Your app, however, seems not to be.

Please use babel to transpile your app and enjoy all the latest ECMAScript goodness.

[Edited for clarity]

jhoermann commented 6 years ago

Thanks for clearing this up. Testing now if this is a viable option for our app. Still I think it would be better to notice that this module is not usable natively with node (without using babel) in the Readme.

Edit: This works for me as a workaround: var ImapClient = require('emailjs-imap-client'); var client = new ImapClient.default(settings.host, settings.port, { ...

felixhammerl commented 6 years ago

Exactly. The module is natively usable. However, then you have to require instead of import in your own code, which has a slightly different semantic.

geek4teck commented 5 years ago

Thanks for clearing this up. Testing now if this is a viable option for our app. Still I think it would be better to notice that this module is not usable natively with node (without using babel) in the Readme.

Edit: This works for me as a workaround: var ImapClient = require('emailjs-imap-client'); var client = new ImapClient.default(settings.host, settings.port, { ...

Works for me too :-)