Cannot read property 'kind' of undefined

System Information
  • Strapi Version: 4
  • Operating System: Mac
  • Database: postgres
  • Node Version: 14.19.1
  • NPM Version:
  • Yarn Version: 1.22.18

During Strapi migration from v3 to v4, I am getting Cannot read property 'kind' of undefined error while running the server.

Error is:

[2022-07-05 13:43:15.579] debug: ⛔️ Server wasn't able to start properly.
[2022-07-05 13:43:15.580] error: Cannot read property 'kind' of undefined
TypeError: Cannot read property 'kind' of undefined
    at isSingleType (/Users/sujay/Documents/cms/node_modules/@strapi/utils/lib/content-types.js:90:25)
    at createRoutes (/Users/sujay/Documents/cms/node_modules/@strapi/strapi/lib/core-api/routes/index.js:6:7)
    at Object.get routes [as routes] (/Users/sujay/Documents/cms/node_modules/@strapi/strapi/lib/factories.js:59:31)
    at /Users/sujay/Documents/cms/node_modules/@strapi/strapi/lib/services/server/register-routes.js:98:14
    at /Users/sujay/Documents/cms/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/sujay/Documents/cms/node_modules/lodash/lodash.js:3032:24)
    at /Users/sujay/Documents/cms/node_modules/lodash/lodash.js:4936:18
    at Function.forEach (/Users/sujay/Documents/cms/node_modules/lodash/lodash.js:9410:14)
    at registerAPIRoutes (/Users/sujay/Documents/cms/node_modules/@strapi/strapi/lib/services/server/register-routes.js:94:7)
    at module.exports (/Users/sujay/Documents/cms/node_modules/@strapi/strapi/lib/services/server/register-routes.js:25:3)
error Command failed with exit code 1.

I have migrated controllers, services and router files.

api/activity/routes/activity.js

const { createCoreRouter } = require("@strapi/strapi").factories;
module.exports = createCoreRouter("api::activity.activity");

api/activity/controllers/activity.js

const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::activity.activity');

api/activity/services/activity.js

const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::activity.activity');

schema.json

{
    "kind": "collectionType",
    "collectionName": "activities",
    "info": {
      "singularName": "activity",
      "pluralName": "activities",
      "displayName": "Activity",
      "name": "activity"
    },
    "options": {
      "increments": true,
      "timestamps": true,
      "draftAndPublish": true
    },
    "attributes": {
      "mobile": {
        "type": "media",
        "allowedTypes": [
          "images"
        ],
        "multiple": false,
        "required": false
      },
      "desktop": {
        "type": "media",
        "allowedTypes": [
          "images"
        ],
        "multiple": false,
        "required": false
      },
      "name": {
        "type": "string"
      },
      "activity_types": {
        "type": "relation",
        "relation": "manyToMany",
        "target": "api::activity-type.activity-type",
        "mappedBy": "activities"
      }
    }
  }
  

I have already tried by deleting node_modules, yarn.lock, build, .cache but no luck yet

can you share your schema file for activity.

@Meher_Chandan I have updated the schema file in the question

Sorry folks, there was an api in which schema file was missing. Removing that fixed the issue

1 Like

My strapi working fine but when I want to modify any records in strapi then application not working. The console I am getting this one for all components records.

Issue Facing:

TypeError: Cannot read properties of undefined (reading ‘code’)

Hi Gajanand, I migrated from strapi 3 to 4 and I can see the content but have same issue as you and getting same error message. Were you able to find a solution?

The solution for me was to add a missing record to the strapi_core_store_settings table, this is what was missing
‘76’, ‘plugin_i18n_default_locale’, ‘“en”’, ‘string’, NULL, NULL

After adding this record it worked.

Hi Sujay, I am getting this same error but all my schema.file for all content-types. Do you know the workaround for this error. I am struggling for 3 days.

I’ve been battling with this issue for 2 days. Finally fixed it and decided to help others whose source of issue might be similar to mine.

If you have a TS project, ensure your tsconfig.json is properly configured. Especially the include array. I tinkered with mine and didn’t realise I bricked Strapi.

{
  "extends": "@strapi/typescript-utils/tsconfigs/server",
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": ".",
    "skipLibCheck": true,
    "resolveJsonModule": true
  },
  "include": ["./", "./**/*.ts", "./**/*.js", "src/**/*.json"],
  "exclude": [
    "node_modules/**",
    "build/**",
    "dist/**",
    ".cache/",
    ".tmp/",
    "src/admin/",
    "**/*.test.*",
    "src/plugins/**",
    "node_modules/**/*.d.ts"
  ]
}