Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Error: ReferenceError: setTimeout is not defined #281

Open
frodoe7 opened this issue Feb 15, 2019 · 4 comments
Open

Error: ReferenceError: setTimeout is not defined #281

frodoe7 opened this issue Feb 15, 2019 · 4 comments

Comments

@frodoe7
Copy link

frodoe7 commented Feb 15, 2019

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

@fs-eire
Copy link
Contributor

fs-eire commented Feb 15, 2019

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(...);

@frodoe7
Copy link
Author

frodoe7 commented Feb 15, 2019

@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
Copy link
Author

frodoe7 commented Feb 15, 2019

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
Copy link
Author

frodoe7 commented Feb 16, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants