strapi-community / strapi-plugin-transformer

A plugin for Strapi Headless CMS that provides the ability to transform the API request or response.
https://market.strapi.io/plugins/strapi-plugin-transformer
MIT License
140 stars 22 forks source link

TypeError: Cannot read properties of undefined (reading 'uid') #67

Closed cjboco closed 1 year ago

cjboco commented 1 year ago

After installing your plugin, I was trying to deploy on Digital Ocean, I kept getting a build failure. Saw an error and then tried starting Strapi locally and got same error:

TypeError: Cannot read properties of undefined (reading 'uid')
    at Object.module.exports [as register] (/Volumes/Strapi/api/node_modules/strapi-plugin-transformer/server/register.js:26:41)
    at Object.register (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/core/domain/module/index.js:47:46)
    at Object.register (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/core/registries/modules.js:33:19)
    at async Strapi.runLifecyclesFunctions (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/Strapi.js:541:5)
    at async Strapi.register (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/Strapi.js:401:5)
    at async Strapi.load (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/Strapi.js:487:5)
    at async Strapi.start (/Volumes/Strapi/api/node_modules/@strapi/strapi/lib/Strapi.js:217:9)

Using Strapi v4.6.1 - Node v16.19.1 - NPM v8.6.3

[EDIT] I added a console.log at line 26 of your register.js file and it looks like UID is not available on one of my collection types:

[Edit2] It is there, sorry. I'll research a little more before posting more info.

cjboco commented 1 year ago

Okay, so I added console.log(' --debug', apis[ct].contentTypes); at line 26 of your register.js. This is right above your const uid = apis[ct].contentTypes[ct].uid; call.

Here's the result:

 --debug {
  global: {
    kind: 'singleType',
    collectionName: 'globals',
    info: {
      singularName: 'global',
      pluralName: 'globals',
      displayName: 'Global',
      description: ''
    },
    options: { draftAndPublish: true },
    pluginOptions: { i18n: [Object] },
    attributes: {
      navigation: [Object],
      footer: [Object],
      createdAt: [Object],
      updatedAt: [Object],
      publishedAt: [Object],
      createdBy: [Object],
      updatedBy: [Object]
    },
    __schema__: {
      collectionName: 'globals',
      info: [Object],
      options: [Object],
      pluginOptions: [Object],
      attributes: [Object],
      kind: 'singleType'
    },
    modelType: 'contentType',
    modelName: 'global',
    connection: 'default',
    uid: 'api::global.global',
    apiName: 'global',
    globalId: 'Global',
    actions: {},
    lifecycles: {}
  }
}
 --debug {}

As you can see, there is nothing in the last '--debug' call. It's an empty object, so no 'uid' exists.

Please let me know how I can help you debug this further, as I don't understand this plugin structure that well.

derrickmehaffy commented 1 year ago

From the Strapi team here, could you possibly share your entire codebase?

cjboco commented 1 year ago

I edited line 21 from

if (!Object.hasOwnProperty.call(apis, ct)) {

to

if (!Object.hasOwnProperty.call(apis, ct) || !apis[ct].contentTypes.hasOwnProperty('uid')) {

and Strapi starts now.

derrickmehaffy commented 1 year ago

(generally speaking, it's not possible for a content-type to not have a UID, we build them during the register phase)

cjboco commented 1 year ago

From the Strapi team here, could you possibly share your entire codebase?

It's a private repo, not 100% sure my client would be down with that, but let me see what I can do.

derrickmehaffy commented 1 year ago

From the Strapi team here, could you possibly share your entire codebase?

It's a private repo, not 100% sure my client would be down with that, but let me see what I can do.

If you need to you can add me to the repo instead, if you need to verify I work for Strapi you can email me at derrick.mehaffy@strapi.io

cjboco commented 1 year ago

From the Strapi team here, could you possibly share your entire codebase?

It's a private repo, not 100% sure my client would be down with that, but let me see what I can do.

If you need to you can add me to the repo instead, if you need to verify I work for Strapi you can email me at derrick.mehaffy@strapi.io

You have access

derrickmehaffy commented 1 year ago

From the Strapi team here, could you possibly share your entire codebase?

It's a private repo, not 100% sure my client would be down with that, but let me see what I can do.

If you need to you can add me to the repo instead, if you need to verify I work for Strapi you can email me at derrick.mehaffy@strapi.io

You have access

not seeing the inv, is this on github?

derrickmehaffy commented 1 year ago

Hmmm still not seeing it :thinking:

derrickmehaffy commented 1 year ago

There we go, got it :)

derrickmehaffy commented 1 year ago

Your home-page folder in ./src/api is empty, that's your problem, you need to delete the home-page folder

derrickmehaffy commented 1 year ago

(it's missing the schema.json file inside of the content-type folder)

cjboco commented 1 year ago

I never said I was a smart! :-)

derrickmehaffy commented 1 year ago

happens to everyone, honestly this is something we should catch and warn about. Welcome to the Strapi ecosystem though :)

derrickmehaffy commented 1 year ago

Let us know if that fixes the issue though :wink:

cjboco commented 1 year ago

I wonder if you can throw an error on that... something like you have a empty api end-point or something. I don't think I ever would have caught that one.

Thank you!

derrickmehaffy commented 1 year ago

Yeah we can do it easily, it should be wrapped in a try/catch and just dump the error and still allow the app to load without that content-type

cjboco commented 1 year ago

Just to confirm, I removed the directory and also reverted the register.js file and it has started perfectly!

[Edit] Deployed to DO with no issues. Thanks again @derrickmehaffy!

ComfortablyCoding commented 1 year ago

Thanks @derrickmehaffy !

JaydeeSale commented 1 year ago

|| !apis[ct].contentTypes.hasOwnProperty('uid')

Can we add this into the source ? seems if we have custom controllers this also breaks the compile, and since custom controllers dont have a schema.json it fails and we cant use this plugin.