google-indexing-script icon indicating copy to clipboard operation
google-indexing-script copied to clipboard

TypeError: Cannot read properties of undefined (reading 'map')

Open fema3832 opened this issue 1 year ago • 1 comments

Hello! Can someone help me why this script is not working for me. I turned on Google Search Console API and Web Search Indexing API. I downloaded the user json which has owner permissions and renamed it service_account.json.

This is the error what i got every time:

> [email protected] index
> node ./src/index.mjs panjandrum.hu

🔎 Processing site: sc-domain:panjandrum.hu
file:///C:/Users/Fema/Desktop/google-indexing-script-main/src/shared/sitemap.mjs:29
  return body.sitemap.map((x) => x.path);
                      ^

TypeError: Cannot read properties of undefined (reading 'map')
    at getSitemapsList (file:///C:/Users/Fema/Desktop/google-indexing-script-main/src/shared/sitemap.mjs:29:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getSitemapPages (file:///C:/Users/Fema/Desktop/google-indexing-script-main/src/shared/sitemap.mjs:33:20)
    at async file:///C:/Users/Fema/Desktop/google-indexing-script-main/src/index.mjs:27:27

Node.js v20.11.0

Thank you very much for your help in advance

fema3832 avatar Jan 27 '24 08:01 fema3832

Hello, I think the JavaScript code's review should be done to know where the error occurs, paying particular attention to the part where it accesses the 'sitemap' property. But first double-check the structure of the response from the Google APIs to ensure that it includes the expected 'sitemap' property. Then try the error handling.

Sivasish48 avatar Jan 27 '24 14:01 Sivasish48

I have the same issue, and I found it needs to submit your sitemap to Google Search Console first, and try again will be works.

  1. Login your Google Search Console.
  2. Click the "Sitemaps" page on the left menu.
  3. Input your sitemap url and submit.
  4. Now try again running this script.

WX20240128-200722@2x

qq280948982 avatar Jan 28 '24 12:01 qq280948982