CLI generate api and uncomment code -Cannot read properties of undefined (reading 'forEach')

Checkout the SS attached.
I modified the file “mono_repo_root_folder/strapi/node_modules/@strapi/strapi/lib/services/server/register-routes.js” ,
in method const registerAPIRoutes = (strapi) => { … } , add a ‘?’ to router.routes.forEach((route) => {…} thereby converting it to router.routes?.forEach((route) => {…}
I used this to run it for time being. However, I still have not found any proper solution.
Let us know if you find anything Or know anything about the // TODO comment in node_module file.