Search code examples
javascriptnode.jsinfluxdb

"TypeError: t.complete is not a function" in Javascript InfluxDB-Client


I am trying to get data from my InfluxDB server in my node.js with influxdb-client, but when I do the query, I get an "TypeError: t.complete is not a function" error. I can see in the console that the client get data and, after, this error is produced.

Code from JS client:

const fluxQuery =
  'from(bucket:"data") |> range(start: 0) |> filter(fn: (r) => r._measurement == "devices") |> filter(fn: (r) => r["_field"] == "wreal1") |> last()';

  queryApi.queryRows(fluxQuery, {
    next(row, tableMeta) {
      const o = tableMeta.toObject(row)
      console.log(o)
    }
});

Console:

{
  result: '_result',
  table: 0,
  _start: '2021-06-17T22:31:04.305309987Z',
  _stop: '2021-06-17T23:02:08.128895474Z',
  _time: '2021-06-17T23:02:07.278424896Z',
  _value: 3159.7,
  _field: 'wreal1',
  _measurement: 'devices',
  disp: '1'
}
C:\Users\usuario\Desktop\proyecto\node_modules\@influxdata\influxdb-client\dist\index.js:1
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("URL"),
.................
return G(t.toString())}const K="function"==typeof Symbol&&Symbol.observable||"@@observable";

TypeError: t.complete is not a function
    at Object.complete (C:\Users\usuario\Desktop\proyecto\node_modules\@influxdata\influxdb-client\dist\index.js:1:4568)
    at Object.complete (C:\Users\usuario\Desktop\proyecto\node_modules\@influxdata\influxdb-client\dist\index.js:1:948)
    at IncomingMessage.complete (C:\Users\usuario\Desktop\proyecto\node_modules\@influxdata\influxdb-client\dist\index.js:16:8791)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
[nodemon] app crashed - waiting for file changes before starting...

I am using 1.14 version from the module, I tried installing 1.13 version but same error.


Solution

  • The query needs to be finished:

    queryApi.queryRows(fluxQuery, {
      next(row, tableMeta) {
        const o = tableMeta.toObject(row)
        console.log(o)
      },
      error(error) {
      console.error(error)
        console.log('\nFinished ERROR')
      },
      complete() {
        console.log('\nFinished SUCCESS')
      },
    });