nodejs-dns icon indicating copy to clipboard operation
nodejs-dns copied to clipboard

TypeError: x.toJSON is not a function

Open SethBlakley opened this issue 3 years ago • 3 comments

Environment details

  • OS: windows10 and also with ubuntu 20.0.4
  • Node.js version: tried with 14.5.0 and with 18.10.0, 18.7.0
  • npm version: 16.4.5, and corresponding versions that match the node version
  • @google-cloud/dns version: 3.0.1, and 3.0.0

Steps to reproduce

  1. Try adding a record to a zone
  2. see error UnhandledPromiseRejectionWarning: TypeError: x.toJSON is not a function, originates from node_modules@google-cloud\dns\build\src\zone.js:333:55

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

typeerror (1).txt

SethBlakley avatar Oct 07 '22 01:10 SethBlakley

Hi @SethBlakley, can you post your code to reproduce and any errors in the Github issue itself? Thank you.

sofisl avatar Oct 13 '22 19:10 sofisl

Hi @SethBlakley, can you post your code to reproduce and any errors in the Github issue itself? Thank you.

I added a txt of my code in the ticket. and the single step to reproduce witch is "Try adding a record to a zone". What else am I missing or is it not in the correct format? I'll give any information needed and thank you for your time in advance.

SethBlakley avatar Oct 14 '22 20:10 SethBlakley

@SethBlakley thank you for the additional information, I've added this to our bug backlog.

bcoe avatar Oct 17 '22 18:10 bcoe

Sorry @SethBlakley, I didn't see that file originally!

I think you need to create a record before adding it, like so:

const aRecord = {
    zone_: "INSERTZONENAMEHERE",
    type: "A",
    metadata: {
      name: 'example.com.',
      data: '1.2.3.4',
      ttl: 300,
      type: "A",
    },
  };

async function main() {
   // First create the record
    let record = await ZONE.record('a', aRecord);
  // Then add it
    await ZONE.addRecords(record)
      .then((res) => {
        console.log(res);
      })
      .catch((err) => {
        console.log(err);
      });
  }

main();

Let me know if this works for you!

sofisl avatar Mar 01 '23 20:03 sofisl

Will close this for now, but please feel free to reopen if it's still an issue.

sofisl avatar Mar 06 '23 19:03 sofisl