Cannot read properties of undefined (reading 'forEach')

System Information
  • Strapi Version: v4.2.0
  • Operating System: Windows

I’m migrating my strapi from v3 to v4 and I got this problem

TypeError: Cannot read properties of undefined (reading 'forEach')  
    at D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\services\server\register-routes.js:98:21
    at D:\Documents\Job\testStrapiV4\my-project\node_modules\lodash\lodash.js:4967:15
    at baseForOwn (D:\Documents\Job\testStrapiV4\my-project\node_modules\lodash\lodash.js:3032:24)
    at D:\Documents\Job\testStrapiV4\my-project\node_modules\lodash\lodash.js:4936:18
    at Function.forEach (D:\Documents\Job\testStrapiV4\my-project\node_modules\lodash\lodash.js:9410:14)
    at registerAPIRoutes (D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\services\server\register-routes.js:94:7)
    at module.exports (D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\services\server\register-routes.js:25:3)
    at Object.initRouting (D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\services\server\index.js:93:13)     
    at Strapi.bootstrap (D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\Strapi.js:415:23)
    at async Strapi.load (D:\Documents\Job\testStrapiV4\my-project\node_modules\@strapi\strapi\lib\Strapi.js:426:5)

I did update the controllers and the services. I did try to delete node_modules and JSON lock file and then run the npm install again, sadly it didn’t work.

Here is my controllers:

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('');

Here is my routes:

const { createCoreRouter } = require('@strapi/strapi').factories;

module.exports = createCoreRouter('');

Here is my service:

const { createCoreService } = require('@strapi/strapi').factories;

module.exports = createCoreService('');

Here is my content-type:

  "kind": "collectionType",
  "collectionName": "group",
  "info": {
    "singularName": "group",
    "pluralName": "groups",
    "displayName": "Group",
    "name": "Group"
  "options": {
    "increments": true,
    "timestamps": true
  "attributes": {
    "project": {
      "type": "relation",
      "relation": "manyToOne",
      "target": "api::project.project",
      "inversedBy": "groups"
    "users": {
      "type": "relation",
      "relation": "manyToMany",
      "target": "plugin::users-permissions.user",
      "inversedBy": "groups"
    "name": {
      "type": "string",
      "required": true
    "categories": {
      "type": "relation",
      "relation": "manyToMany",
      "target": "api::category.category",
      "inversedBy": "groups"
    "meetings": {
      "type": "relation",
      "relation": "manyToMany",
      "target": "api::meeting.meeting",
      "mappedBy": "groups"
    "googledocouidshared": {
      "type": "string"
    "googledocouid": {
      "type": "string"
    "documents": {
      "type": "relation",
      "relation": "oneToMany",
      "target": "api::googledocument.googledocument",
      "mappedBy": "group"


Were you able to figure our a solution to this? I am also stuck on this?

Any help will be appreciated

1 Like

I had file named 01-custom-policy.js inside routes directory (which I had included to test policies). Upon removal this issue got resolved.

Just see if you have some redundant files & remove them.


I got the same issue with a new strapi project.

can you please tell if you know anything about the TODO comment in the following screenshot

I use Vim and had an invisible .swp file within the routes directory which caused this issue. Check for invisible files if you’re also seeing this error

I would suggest you to check controller, router,and service s files. if appropriate code is written.

Easier way: Put Console log in for each and you will find an exact space where issue occurs in your modified files.
Where ever error occurs you see like below:
{ ‘article’: [Function (anonymous)] }