google-indexing-script
google-indexing-script copied to clipboard
TypeError: Cannot read properties of undefined (reading 'map')
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
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.
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.
- Login your Google Search Console.
- Click the "Sitemaps" page on the left menu.
- Input your sitemap url and submit.
- Now try again running this script.