standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

Cannot make it work with CJS singletons #783

Closed kavillo closed 5 years ago

kavillo commented 5 years ago

I'm adding esm to an existing node project. The project is currently using modules as singletons, in the following way:

Module: scrapedUrlsController.js

class scrapedUrlsController {
 constructor() {
        this.data = new DatabaseObject();
    }
   doSomething() {
       this.data.doSomething();
   }
}
module.exports = new scrapedUrlsController();

In another .js file I use the module as:

const scrapedUrlsController = require('scrapedUrlsController');

scrapedUrlsController.doSomething();

I was not planning to change these modules, however, once esm kicks in, they do not work anymore.

When I call "doSomething", this becomes a Proxy-ed object that doesn't give access to it properties, so data becomes not accessible. Am I doing something wrong?

jdalton commented 5 years ago

Hi @kavillo!

Could you create a small repro repo so I can better investigate the issue?

kavillo commented 5 years ago

Hi @jdalton , thanks for quick easter response!

Uploaded a minimal repository here: https://github.com/kavillo/esmrepro

jdalton commented 5 years ago

Thanks @kavillo!

I can reproduce the issue and have identified the problem : )

Update:

Actually, this is already fixed by https://github.com/standard-things/esm/commit/a48ba8a8a9bfcd62e4309222dcc2f217200a1f34 on our master branch.

kavillo commented 5 years ago

Thanks! Got the master branch and confirm it works in my scenario.

On Mon, Apr 22, 2019 at 3:20 AM John-David Dalton notifications@github.com wrote:

Closed #783 https://github.com/standard-things/esm/issues/783.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/standard-things/esm/issues/783#event-2290393665, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBRJF4FOK4WHQSQF4HL4XDPRUHGPANCNFSM4HHMCGZQ .

-- Gian Camillo Vezzoli