harry1064 / APNS2

MIT License
1 stars 6 forks source link

TypeError: Notification is not a constructor #6

Open saggymac opened 7 years ago

saggymac commented 7 years ago

Using ... node v8.0.0 npm 5.0.1 apns-http2 1.0.5 (globally installed, with symlink to local)

This is easily recreate-able by just using the sample code from this project's README.md.

const note = new Notification( token, pushBody);
             ^
TypeError: Notification is not a constructor
    at Object.<anonymous> (/Users/dude/src/forks/tmp/scripts/push-prod.js:24:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
wcyyo commented 6 years ago

Same problem with me.Have u deal it?

harry1064 commented 6 years ago

try to use const Notification = APNS.Notification(); instead of const Notification = APNS.Notification;.

Let me know if problem still exist.

wcyyo commented 6 years ago

I solved this problem use ‘let Notification = require('./notification.js');’ And i push sucess to my app use my devicetoken. But when there are lots of msgs,(i use for methods and ngrinder to do some stress test) then The server will shut down with this error‘’ image

harry1064 commented 6 years ago

Are you creating new apnsClient on each iteration ?

wcyyo commented 6 years ago

Yes!

harry1064 commented 6 years ago

create apnsClient outside the loop and call apnsClient.send method inside the loop. Let me know if still problem exist.

wcyyo commented 6 years ago

Thanks i will try

harry1064 commented 6 years ago

is it resolved @wcyyo