Cannot read property 'singularName' of undefined

System Information
  • **Strapi Version4.06:
  • **Operating SystemMac:
  • **DatabasePostgres:
  • **Node Version14.18.1:
  • **NPM Version6.14.15:
  • **Yarn Version1.22.10:

This error seems to have appeared from nowhere as it was working fine when I last worked on this project 6 days ago.

When I run npm run develop I get this error:

Cannot read property 'singularName' of undefined
TypeError: Cannot read property 'singularName' of undefined

The error is pointing to /node_modules/@strapi/strapi/lib/core/loaders/apis.js:48:21

const validateContentTypesUnicity = apis => {
  const allApisSchemas = Object.values(apis).flatMap(api => Object.values(api.contentTypes));

  const names = [];
  allApisSchemas.forEach(({ schema }) => {
    if (schema.info.singularName) {
      const singularName = _.kebabCase(schema.info.singularName);
      if (names.includes(singularName)) {
        throw new Error(`The singular name "${schema.info.singularName}" should be unique`);
      }
      names.push(singularName);
    }

    if (schema.info.pluralName) {
      const pluralName = _.kebabCase(schema.info.pluralName);
      if (names.includes(pluralName)) {
        throw new Error(`The plural name "${schema.info.pluralName}" should be unique`);
      }
      names.push(pluralName);
    }
  });
};

Can anybody help? I have been trying to fix this for too long :frowning:

When I console.log(allApisSchemas) there seems to be an empty schema:

const validateContentTypesUnicity = apis => {
  const allApisSchemas = Object.values(apis).flatMap(api => Object.values(api.contentTypes));
  **console.log(allApisSchemas)**
  const names = [];
  allApisSchemas.forEach(({ schema }) => {
    //   console.log(Object.keys(schema))
    if (schema.info.singularName) {
      const singularName = _.kebabCase(schema.info.singularName);
      if (names.includes(singularName)) {
        throw new Error(`The singular name "${schema.info.singularName}" should be unique`);
      }
      names.push(singularName);
    }

    if (schema.info.pluralName) {
      const pluralName = _.kebabCase(schema.info.pluralName);
      if (names.includes(pluralName)) {
        throw new Error(`The plural name "${schema.info.pluralName}" should be unique`);
      }
      names.push(pluralName);
    }
  });
};
[
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'authors',
      info: [Object],
      options: [Object],
      pluginOptions: {},
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  {
    lifecycles: { afterCreate: [AsyncFunction: afterCreate] },
    schema: {
      kind: 'collectionType',
      collectionName: 'blogs',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {}
  },
  {
    lifecycles: {},
    schema: {
      kind: 'collectionType',
      collectionName: 'categories',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {}
  },
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'comments',
      info: [Object],
      options: [Object],
      pluginOptions: {},
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  {
    schema: {
      kind: 'singleType',
      collectionName: 'globals',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'helps',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'help_categories',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'landing_pages',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  },
  **{ schema: {}, actions: {}, lifecycles: {} },**
  {
    schema: {
      kind: 'collectionType',
      collectionName: 'tags',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object]
    },
    actions: {},
    lifecycles: {}
  }
]

This appears to be the root of the problem but I can’t see where this empty object is being generated from!

Fixed (well sort of). No idea why but I had to delete the ‘page’ collection type to make it work. Not ideal but won’t take me long to create the content type again.

4 Likes

This error occurs when you have an empty collection folder.

18 Likes

Thanks @BorisShulyak, that solved the problem for me too. For me this happened when I created some demo collections / components in admin and then I did hard git reset. Folders, though empty, remained created.

1 Like

In my case I’ve just created a custom controller inside …/api/MY_API_NAME/controllers/newController.js

Removing node_modules and lock files did not solve the issue

You can try remove all project and reinstall with actually new source

Yes, thats it:

  1. I created custom collections
  2. After that I deleted the files by deleting with git
  3. The folders aren’t deleted.

And so I got the error.

1 Like

Gracias, mi sirvio a mi tambien!