Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nihiser opened this issue May 27, 2020 · 15 comments

Comments

@nihiser
Copy link

nihiser commented May 27, 2020

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

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

@MrAlekhin
Copy link

MrAlekhin commented May 28, 2020

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

@haoliu-amp
Copy link
Contributor

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

@MrAlekhin
Copy link

MrAlekhin commented May 28, 2020

@haoliu-amp the same as here.

    const client = Amplitude.init(config.amplitude.key);
    client.logEvent({
      event_type: "Node Event",
      user_id: "Test",
    });

@MrAlekhin
Copy link

MrAlekhin commented May 28, 2020

@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.

const req = https.request(this._options.serverUrl ?? AMPLITUDE_SERVER_URL, requestOptions);

@haoliu-amp
Copy link
Contributor

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

@MrAlekhin
Copy link

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

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

@MrAlekhin
Copy link

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

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

+1 Having the same issue.

@haoliu-amp
Copy link
Contributor

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

@haoliu-amp node version 13.9 here

@haoliu-amp
Copy link
Contributor

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

nihiser commented May 28, 2020

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

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

No branches or pull requests

4 participants