wanasit / google-calendar

Google Calendar API connection in Node.js
MIT License
230 stars 54 forks source link

Node crashes when fetching calendar event list #29

Open amerikan opened 2 years ago

amerikan commented 2 years ago

Node 14+

const calendar = new gcal.GoogleCalendar(accessToken);

calendar.events.list(
// arguments
);

Node crashes with the following error:

 Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented
0|www    |     at new NodeError (node:internal/errors:371:5)
0|www    |     at Readable._read (node:internal/streams/readable:651:9)
0|www    |     at Readable.read (node:internal/streams/readable:487:10)
0|www    |     at maybeReadMore_ (node:internal/streams/readable:638:12)
0|www    |     at processTicksAndRejections (node:internal/process/task_queues:83:21) {
0|www    |   code: 'ERR_METHOD_NOT_IMPLEMENTED'
0|www    | }
0|www    | Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented
0|www    |     at new NodeError (node:internal/errors:371:5)
0|www    |     at Readable._read (node:internal/streams/readable:651:9)
0|www    |     at Readable.read (node:internal/streams/readable:487:10)
0|www    |     at maybeReadMore_ (node:internal/streams/readable:638:12)
0|www    |     at processTicksAndRejections (node:internal/process/task_queues:83:21)
amerikan commented 2 years ago

I just wanted to open this issue in case anyone else gets this problem. After troubleshooting my entire app for several days, it turns out it was a dependency that google-calendar uses called needle.

Solution: To fix this issue I forked this repo and used a newer needle version for it. Another option if you're using newer npm version is to use the override option.

You can do those workarounds unless the PR reference in the next paragraph gets merged. The needle version I arbitrarily used was version 2.9.1 and it worked.

@wanasit I think merging https://github.com/wanasit/google-calendar/pull/23 would be a good start.

firststef commented 2 years ago

I have the same problem. This didn't work for me, i tried changing the needle version even with overrides even manually, i don't think that's the solution.

amerikan commented 2 years ago

I have the same problem. This didn't work for me, i tried changing the needle version even with overrides even manually, i don't think that's the solution.

Do you have npm v8.3.0? Because that's when override feature was added. Though a few minor versions later it was buggy so override didn't quite work. What I had to do is just forked this repo and manually make the change to the needle version. Then I just install from the fork i.e. npm i https://github.com/user_name/node_project_name.

Though what I ultimately did was just to use googleapis package. Here's a snippet, but you can basically do everything this package does plus more.

const { google } = require("googleapis");

const gcalendar = google.calendar({
  version: "v3",
});

// .......
// specific example
 const response = await gcalendar.freebusy.query({
  oauth_token: accessToken,
  requestBody: {
    timeMin: timeMin.format(),
    timeMax: timeMax.format(),
    timeZone,
    items: [{ id: "primary" }],
  },
});
firststef commented 2 years ago

I took another look at it and indeed my npm version was v7. I did install your forked repo but for some reason that did not work either, i managed to get it to work with npm-force-resolutions. Thanks.