I’ve realised my error and the problem has been sorted out
I had a copy of the old router in the same routes folder with the postfix “.old”, seems like that was getting picked up by Strapi and causing it to crash.
I have installed the new strapi v4 typescript and getting the same issue.
However it is a new project altogether and there is nothing yet added.
The strapi server starts for the first time.
Then I created the admin account.
Directed to admin dashboard.
And after adding a content-type , when clicked on save it will fail to restart strapi.
Getting the same error “cannot read properties of undefined (reading 'forEach')”
Points to be Noted:
This works smoothly on local machine (Windows 11)
Gives issues on local machine (Windows 11) when using inside mono_repo
If I modify 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) => {…} then the entire flow starts working properly.
Sample of the SS of file in node_modules attached where i added my modification:
However this is just a temporary fix for running on local and not a proper solution.
Also there is a TODO note inside this node_modules file.
Please let me know if you know anything about this, or can redirect to any link/page/forum etc.
It will be a great help, as rest of my plans are already in motion regarding implementation and deployment.
Stuck on this since couple of weeks. may have to switch to different cms if no solution is found.
As was the case with me, this is usually caused by extra route files in the routes folder, can you please double check that you don’t have any extra files in the routes folder?
@zackmorris Checked for extra routes. nothing of the sort exists.
Retried setup from scratch on Ubuntu, in monorepo and all is working fine at the moment. Probably it has some issues when initializing from Windows. Will update if I come across more info about it.
Update:
no issue found.
maybe a patch update or something was added, after which the error for routes resolved itself
current version: “@strapi/strapi”: “4.5.4”
Working smmothly on Ubuntu | Mac | Windows
cc @zackmorris