napajs icon indicating copy to clipboard operation
napajs copied to clipboard

Error: ReferenceError: setTimeout is not defined

Open frodoe7 opened this issue 6 years ago • 4 comments

The issue occurs when calling zone.broadcastSync();

  • exactly here in my codes
zone.broadcastSync(() => {
      global.module = require('module');
});

and here inside napajs source code (zone-impl.js file)

ZoneImpl.prototype.broadcastSync = function (arg1, arg2) {
        var spec = this.createBroadcastRequest(arg1, arg2);
        var result = this._nativeZone.broadcastSync(spec);
        if (result.code !== 0) {
            throw new Error(result.errorMessage);
        }
    };

I tried to find a solution without opening a new issue - but it looks like this library does not have a big community so I hope to have a quick help

frodoe7 avatar Feb 15 '19 04:02 frodoe7

Module timer does not work like that in Node.js.

To use timers functions in your module ( that runs in zones), simply use require('timers') in zones will work. for example:

require('timers').setTimeout(...);

fs-eire avatar Feb 15 '19 06:02 fs-eire

@fs-eire what's this ? - I only use the standard functions inside napa .broadcast and .execute these issues maybe inside napa source code - not mine

frodoe7 avatar Feb 15 '19 09:02 frodoe7

Module timer does not work like that in Node.js.

To use timers functions in your module ( that runs in zones), simply use require('timers') in zones will work. for example:

require('timers').setTimeout(...);

@fs-eire I'm running zone.execute inside for loop - do you think , this is the problem ?

frodoe7 avatar Feb 15 '19 16:02 frodoe7

this library has some compatibility issues with node version +8.5 it worked well with me after downgrading to (version 8.4.0)

frodoe7 avatar Feb 16 '19 05:02 frodoe7