node-onesignal icon indicating copy to clipboard operation
node-onesignal copied to clipboard

TypeError: OneSignalClient is not a constructor

Open HostOnNet opened this issue 7 years ago • 4 comments

> root@ip-172-31-41-200:/usr/share/nginx/html/webapps/node_modules/node-onesignal/dist# node
> var OneSignalClient = require('node-onesignal');
undefined
> var client = new OneSignalClient('1', '2');
TypeError: OneSignalClient is not a constructor
    at repl:1:14
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)
> 

Node version is

# node --version
v7.10.0
#

Any idea how to fix this error ?

EDIT: i tried on v8.0.0, got same error

HostOnNet avatar Jul 01 '17 16:07 HostOnNet

Same issue here

spacegraym3 avatar Jul 03 '17 06:07 spacegraym3

I got it fixed by using

const OneSignalClient = require('node-onesignal').default;

HostOnNet avatar Jul 03 '17 07:07 HostOnNet

I believe this has something to do with the Babel transpilation and Node 7/8. I'll try to look at this sometime soon and resolve it.

Thanks for reporting!

jamesdixon avatar Jul 03 '17 17:07 jamesdixon

Thanks @HostOnNet and @jamesdixon. @HostOnNet, your workaround worked beautifully. Thank you.

spacegraym3 avatar Jul 04 '17 03:07 spacegraym3