amplitude / Amplitude-Node

Server-side Node.js SDK for Amplitude
MIT License
67 stars 20 forks source link

TypeError: The "listener" argument must be of type Function. Received type object #7

Closed nihiser closed 4 years ago

nihiser commented 4 years ago

TypeError: The "listener" argument must be of type Function. Received type object

My code block is nearly identical to the example:

    const client = Amplitude.init(config.amplitude.key);

    client.logEvent({
      event_type: "Node Event",
      user_id: "Test",
    });

I am in a TypeScript project and making the call in ComponentDidMount. Additionally, I added the @amplitude/types package (Should update your README for that).

Any assistance would be appreciated!

haoliu-amp commented 4 years ago

It looks correct to me. Did you add @amplitude/node package as well?

MrAlekhin commented 4 years ago

Hello! having the same issue with AMP. added only @amplitude/node

haoliu-amp commented 4 years ago

Could you provide more details about this error? Like which line triggered this?

MrAlekhin commented 4 years ago

@haoliu-amp the same as here.

MrAlekhin commented 4 years ago

@haoliu-amp did you do any changes to the logEvent method recently?

maybe there has to be || instead of ??. because as I understand you want to provide a default value. https://github.com/amplitude/Amplitude-Node/blob/7c83bf9e18b9675d4699d221498e8a230bc08124/packages/node/src/nodeClient.ts#L59

haoliu-amp commented 4 years ago

@MrAlekhin Which version are you using btw? Also would you mind share the stacktrace too?

MrAlekhin commented 4 years ago

@haoliu-amp version 0.3.1

TypeError: "listener" argument must be a function
    at ClientRequest.once (events.js:340:11)
    at new ClientRequest (_http_client.js:174:10)
    at Object.request (http.js:39:10)
    at Object.request (https.js:245:15)
    at NodeClient.logEvent (/Users/artem/FitCompete/fitcompete_api_v2/node_modules/@amplitude/node/dist/nodeClient.js:47:25)
    at Post.findById.then (/Users/artem/FitCompete/fitcompete_api_v2/server/routes/post_routes.js:84:19)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
haoliu-amp commented 4 years ago

@MrAlekhin Thank you! Would you like to try 0.2.0 real quick to see if that version works for you?

MrAlekhin commented 4 years ago

@haoliu-amp looks like the same error 🤷‍♂️

TypeError: "listener" argument must be a function
    at ClientRequest.once (events.js:340:11)
    at new ClientRequest (_http_client.js:174:10)
    at Object.request (http.js:39:10)
    at Object.request (https.js:245:15)
    at NodeClient.logEvent (/Users/artem/FitCompete/fitcompete_api_v2/node_modules/@amplitude/node/dist/nodeClient.js:31:25)
    at Post.findById.then (/Users/artem/FitCompete/fitcompete_api_v2/server/routes/post_routes.js:84:19)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

package.lock

 "@amplitude/node": {
      "version": "0.2.0",
      "resolved": "https://registry.npmjs.org/@amplitude/node/-/node-0.2.0.tgz",
      "integrity": "sha512-zod9xiz7So14KyFMYu6/saSLn2iYGpkKxGvdEHOZCXau1yNb/zBcMFSb6FaxkN4sj7ZEaQMI7ATD18Z5Vuk/Mg==",
      "requires": {
        "tslib": "^1.9.3"
      }
    },
haoliu-amp commented 4 years ago

Wonder what version of node are you using? Mine is v12.16.1. It looks very similar to https://www.reddit.com/r/learnjavascript/comments/fshsy5/how_do_i_fix_typeerror_listener_argument_must_be/

mc-lovin commented 4 years ago

+1 Having the same issue.

haoliu-amp commented 4 years ago

@MrAlekhin @nihiser @nihiser What version of node are you guys using? Look like it might be because of the node version compatibility issue.

mc-lovin commented 4 years ago

@haoliu-amp node version 13.9 here

haoliu-amp commented 4 years ago

@mc-lovin @MrAlekhin @nihiser Hey all, I published a new version v0.3.2. Mind try it out? Thanks! https://www.npmjs.com/package/@amplitude/node

nihiser commented 4 years ago

@haoliu-amp I am on node 13.5.0. Just updated and working fine! Thanks!